DEV Community

Taylor Overturf
Taylor Overturf

Posted on

10 Terminal Commandments for Coding Newbies

The terminal can be an intimidating place for anyone, like me, who has spent most of their life living in a ✨Graphical User Interface✨ paradise.

In the GUI, it seems like nothing can really go that wrong. However, on the command line, it feels like a single cat-on-keyboard moment can bring everything crashing down. 🐱🔥

It is my belief that the terminal itself is not what frightens us, but the unfamiliarity of it all. Once you build up your confidence, the terminal can, and will, be your new best friend. 👯 I promise!

The first time I entered the terminal, I had no idea where I was. You don't believe me? Look at the first 15 commands I ever ran:
Image description Unfortunately, hello and where am i, yielded no results. You know what did? Making a ton of mistakes, which I like to call, "practice." (I really got my ls practice in here, see lines 6 to 9).

So, here are my Top 10 Terminal Commandments. These helped me become more comfortable working on the command line, and I hope they help you, too! 💛

1. history

If you're anything like me, you routinely forget the command you ran 5 seconds ago. Run history to get a friendly reminder. You will see all the commands you have previously run. And, if you don't mind scrolling for several minutes, try to find your first 15 commands by going all the way up. Perhaps you, too, wondered: where am i? 🌍

2. exit

Image description This is a best practice that I turned into a habit very early on in my coding journey and I'm grateful I did. By using exit at the end of every session, you are setting yourself up for success later on when it will be important to exit out of multiple servers and live ports. Use exit whenever you're done in the terminal, instead of just quitting or x-ing out. Your future coder-self will thank you! 🙏

3. mv old-file-name-you-dont-want new-file-name-you-do-want

I can't tell you how many times I've misspelled something and thought, "Oh well, I guess it will just be called main-directury for the rest of my life." 🤷‍♀️ For some reason, as a coding newbie, I find it scarier to delete and edit than it is to create. However, don't be fearful of the mv command. You can easily rename your files for times when you have a typo or simply realized there's a better name out there for your project or file.

4. touch new-file-name

🏆 This one gets the award for Cutest Command, touch whenever you want to create a new file. Not to be confused with the less cute, mkdir which will just create a folder (directory).

5. pwd

Print Working Directory or pwd is the command I was looking for when I ran where am i. It will tell you exactly where you are within your file structure! This is helpful for when you want to confirm your location before running another command.

6. ls

List all the contents of a folder. This is extremely helpful as there is no graphical interface showing you all your files, you either need to remember (not going to happen!) or see what your options are. 🧐

7. cd

Move into a folder. ⬇️ Think of it as moving level down within your file structure.

8. ..

Move out of a folder. ⬆️ Think of it as moving one level up within your file structure.

9. CMD + t

Did you know, just like your browser, you can also open a new tab in your terminal? Maybe you cd-ed into the depths of one folder and now you want to move back out .. without losing your spot. The CMD + t action will open a new tab where you currently are (which is different than opening up the terminal application on your computer). Use it when you want to be in two places at the same time! 🪄

10. CTRL + c

Did you just start running something that you instantly regret? 😱 Try the action CTRL + c to clear. This will become handy later with Git and installations and servers and other levels of chaos, but it is helpful to hardwire into your brain now so that you always have an escape plan!

Yes, the terminal can be a scary place for us beginners. But, every time you run ls a coding fairy gets its wings. So ls all day long, my friends! I guarantee you will start to feel more comfortable as you practice these 10 Terminal Commandments. Finally, love thy coding newbie as thyself–comment, re-post, print, bookmark, subscribe or share this post!

Discussion (29)

Collapse
jonrandy profile image
Jon Randy

touch is actually for updating the file access or modification time. The fact that it happens to create the file if it doesn't exist is merely a convenient side effect

Collapse
projaymmer profile image
Jay Nguyen

Oh shoot. My course did not share that fact. Thanks, Jon!

Collapse
stackoverturf profile image
Taylor Overturf Author

Thank you so much, Jon Randy! I appreciate that you took the time to comment.

Collapse
aschwin profile image
Aschwin Wesselius

I like that you use the word "commandments" instead of commands. At least these are not written in stone tablets....

It might help to mention that this goes only for POSIX compliant operating systems. Not for Powershell or DOS prompts.

But I agree that it can be daunting to start working with the terminal on UNIX/Linux/OSX/FreeBSD etc.

However, the power lies in the fact that these commands can be executed from scripts and thus you can program any flow of execution. This can't be done in a GUI without bothering setting up some advanced GUI interpretation tool. Which doesn't scale properly is mundane and error prone when the GUI changes.

The terminal hardly changes. These tools have been around for decades and decades.

To me, the productivity rises when I can automate stuff from the terminal using scripts. Heck, this is where most DevOps etc. finds its own roots.

Nice to see that even newbies dare to look into it, picking it up and even writing posts about it!

Collapse
napcoder profile image
Marco Travaglini

You know the sensation when you need to re-execute that very complicated command you run few days or week ago and you cannot remember anything but a word? history | grep that-word saved my life a lot of time

Collapse
rbgrouleff profile image
Rasmus Bang Grouleff

In Bash you are also able to search in your history with CTRL+r :)

Collapse
napcoder profile image
Marco Travaglini

I have to remember this one, thanks

Collapse
aschwin profile image
Aschwin Wesselius • Edited on

Some more very useful things on the terminal. Be ready, since these might shock you!

The history command has been mentioned before. It will indicate also a number in front of the commands entered. If you take this number after the exclamation mark it will execute that command again. You can even pipe these.

Let's say from Taylor's history command we take entry 14 and 15, to create the folder and to list the content inside the current folder:

$ !14 && !15
Enter fullscreen mode Exit fullscreen mode

It should execute both commands (mkdir myFolder and ls) consecutively. The && is used to make sure the command ends properly first before trying to execute the next command. This is somewhat advanced Bash, but still very helpful to understand and use.

Ok, another useful feature in Bash, is the up arrow. This way you can "browse" a bit in your history. Probably you already know this, but if not this is a God send! This way you can find the command that was working, edit it a bit and hit ENTER again to execute it. If you have to do some commands over and over again a couple of times with some slight changes, this helps out a lot of the repetitive and boring things. Boring means loss of concentration, loss of concentration means less fun. We don't want boring, we want productivity and results. We can do this!

And never forget to use the TAB autocompletion functionality!

For advance use of the terminal, the Z-shell (zsh) is quite powerful where most commands have autocompletion, syntax hightlighting and better display of common elements etc. This way, using Git will be a breeze because the autocompletion gives even suggestions to the possible arguments you might want to enter.

Have fun and hack the planet!

Collapse
airmind profile image
Alex Ágreda

Another neat trick you can use is !! to get the last command you executed before, this is pretty convenient whenever you want to execute it but with another command, example:

you just used
git status

and now you want to add everything to stage and see the status you can type
git add . && !!

and the shell will "translate" it to
git add . && git status

Collapse
goodevilgenius profile image
Dan Jones

This is very unclear on how to use ... It's not a command itself. If you try it, you'll just get a "command not found" error.

You need cd ..

Also, cd by itself will send you back to your home folder. Normally, you need to put the directory name in there: cd subfolder

Collapse
m1keym profile image
Mikey

I have recently started using the command line and this made me chuckle especially there 'where am i' and was extremely informative as well.

I've come across a problem I've yet to be able to fix, I wonder if you might have a solution.

When you're working with git and you're about to commit and type out a message but you forget one side of the "" around the message - my terminal goes wild and I haven't been able to figure out what to do except close and start again which is annoying.

Let's say I type git commit -m "initial commit

and press enter without closing the quotation mark I get just get

and nothing I press works, is there are cmd to fix it?

Collapse
aschwin profile image
Aschwin Wesselius

Most of the time you can just add the closing quotation mark. It might include the tailing carriage return/linefeed (\n) into the commit message, but that's not that much damage done right? You can also update the commit message, which I hardly do so I don't know how to do it without looking it up for you.

Collapse
airmind profile image
Alex Ágreda

You can edit your last commit message with git commit --amend

Collapse
kamilzag profile image
KamilZag

Have you tried
Ctrl + c
?
It should help i think

Collapse
stackoverturf profile image
Taylor Overturf Author • Edited on

Hi Mikey, I know exactly what you're talking about and I have made the mistake of forgetting my ending quotation mark many times!

I agree with KamilZag, CRTL + C will allow you to return to the normal command line and get out of that weirdness.

I also just saw Aschwin's great explanation, yes, if you notice your error soon enough, I have found that I can add the ending " even if I've pressed enter. However, I did not know I could update my commit message, so thank you for that!

Thread Thread
m1keym profile image
Mikey

Thank you all so much for your help.

I've done it a few times and then I just end up staring blankly at the screen like 'WTF do I do' hit a few keys then close the terminal, but then I have to navigate all the way back to where I was because I don't know any other way. I contemplated Googling it but couldn't think of what to ask without writing an essay.

I appreciate the help! :)

Collapse
nueeardente profile image
Edgar Carlos

Thank you for this article.
For me, the most indispensible commands (besides some of the ones in this article) are:

  1. cat combined with grep -i (when you are quickly looking for something or some pattern in a file)
  2. grep (many regex options)
  3. tail (when going through logs in linux)
  4. more
  5. which and last but not least
  6. man (for looking up how to use the commands mentioned here)
Collapse
dozykeys profile image
Duru Chidozie

it's worth it...thumbs up

Collapse
goodevilgenius profile image
Dan Jones

I think you've confused iTerm or Terminal.app with "terminal". Cmd-t is an iTerm (and other terminal emulator) shortcut for opening a new tab. It's not universal, and has nothing to do with the terminal itself, but rather, with the terminal emulator you're using.

Collapse
projaymmer profile image
Jay Nguyen

These are some dope commandments, bruh. Unlike the Almighty, I shall follow you. Thanks for sharing.

Collapse
xiaoeyun profile image
Xiao_e_yun

No whereami,but you have whoami

Collapse
mrwensveen profile image
Matthijs Wensveen

alias whereami=pwd

Collapse
astorrer profile image
Aaron Storrer

How about "Commands newbies should never type." Or, most dangerous powerful commands.

rm (or anything with -r or -R)
chmod
chown
mv (You did mention it's use but not why to fear it.)

Collapse
sturlabragason profile image
sturlabragason

Nice post! My favorite is CTRL+R 🔥

Collapse
dozykeys profile image
Duru Chidozie

Nice read...it was worth it

Collapse
drvy profile image
Dragomir Yordanov

Note: CTRL + C does not "clear" the terminal. It sends an "Interrupt" (SIGINT) signal to the current program. Also, the program can chose to ignore it.

Collapse
moscow0201 profile image
UCan

thank you so much

Collapse
thiagomg profile image
Thiago Massari Guedes

A nice shortcut for exit is Ctrl+D - It is also satisfying for lazy people such as myself

Collapse
whobeu profile image
Robert G. Schaffrath

I usually set IGNOREEOF=4 (or higher) due to having gotten logged out too many times accidentally. Type CTRL+D to exit an application and it seems unresponsive so I hit it again. Then it actually wakes up and I have entered two CTRL+D's with the net result being the shell getting the second CTRL+D LOL.