DEV Community

Sal Hernandez
Sal Hernandez

Posted on

These are a few of my favorite: Terminal Shortcuts

Terminal: an interface where the user types and executes text based commands.

ISSA Terminal

I’ll admit that when I first opened the terminal in 2014, I disliked it. At the time, I strongly believed that using a Graphical User Interface, such as Finder on Mac, was much faster for things like deleting, copying, and creating files and folders. The tutorials and articles I would read kept insisting that the terminal was 🔑, though, so I kept going.
I’m glad I pushed through and kept learning to use the terminal! Eventually, with practice and consistency, the understanding and speed came. Now I barely use the GUI for managing my file system.
That said, the road wasn’t all smooth. There were a lot of terminal commands thrown at me during my journey. How was I supposed to memorize all of them??!!? At once?!?!

To prevent you from going through the same anxieties. I compiled a list of my Top Fave ❤️ Terminal shortcuts. 😁

ls List files and directories (Folders)


cd Change directory
pwd Print Working Directory (Shows the full pathname of the current working directory)


touch Create a new file


mkdir Create a new directory


cp Copy files or directories


mv Move (rename) files or directories


rm Remove files
rm -r Remove Directories & files in
Note: Therm command is really powerful. It deletes files/directories without recovery. (It doesn’t go to the trash bin)


Ctrl + A Gets the cursor at the beginning of the line
Ctrl + E Gets the cursor to the end.


Cmd + k (Mac) `Ctrl + L (Linux/Mac) Clears the Terminal Screen


And now for my absolute favorite ❤️: Tab auto-completion!

If you’re trying to remember a command, type at least one letter and hit tab twice and it will show you all the commands available based on the typed characters. If you type enough characters and only one match is left then it’ll auto-complete it for you. This works with all UNIX commands and even your file system.

Now go on and jump into your terminal, start playing with it & work your way towards becoming the terminal-ator. 😎


If you liked this post, make sure to hit the hit the green heart! 💚
For more puns and code tips follow my journey on twitter @clickclickonsal
Join the Color Coded slack community by visiting our site and stay in the loop.

This article originally published on the Color Coded Medium publication

Oldest comments (54)

Collapse
 
pmogi profile image
Patrick Mogianesi

When my friend showed my tab auto-complete it changed my life lol

Collapse
 
clickclickonsal profile image
Sal Hernandez

Word! Tab auto-complete, completes me 😂❤️

Collapse
 
anarchyrucks profile image
Ashish Acharya

it is good to alias rm to trash command.. it will become a life saver decision 😊

Collapse
 
clickclickonsal profile image
Sal Hernandez

Typically when I alias things I will alias them to something shorter. I see no reason to alias rm specifically.
when I use alias it be something like this
git checkout = gc

It's about reducing key strokes 😃

Collapse
 
anarchyrucks profile image
Ashish Acharya • Edited

I meant alias rm="trash"

Collapse
 
bensheldon profile image
Ben Sheldon

CTRL-r to search through your bash command history:

unix.stackexchange.com/questions/7...

Collapse
 
silwing profile image
Silwing

This is easily my favorite as well.

Collapse
 
clickclickonsal profile image
Sal Hernandez

Oh, this is really cool! I'm gonna keep this in mind next time I run into this!!!!

Tanks for the tip!!!

Collapse
 
ennor profile image
Enno Rehling (恩諾)

Sometimes even faster, !ls repeats the last command that started with ls (or any other sequence of characters).

Collapse
 
palle profile image
Palle

The z command is one of my favorites. You just type z dir and it searches all directories you visited for a directory name containing dir and jumps to the best match.

Collapse
 
clickclickonsal profile image
Sal Hernandez

I kept the post tailored to beginners to make it easier to get familiar with the terminal.

The z command looks pretty cool but it doesn't have documentation on how to set it up, and this is one of the things I found hard for me in the beginning. I can figure out how to it up but not everyone can.

Maybe it would be cool for you to write a blog post on it ? Or maybe even submit a pull request on how to set it up.

Collapse
 
palle profile image
Palle • Edited
brew install z

Then add

. `brew --prefix`/etc/profile.d/z.sh

To your .zshrc file.
That's it.

I used this blog post to turbocharge my terminal. (The post recommends iTerm over the classic Terminal but everything works as expected in Terminal)

Collapse
 
rhymes profile image
rhymes • Edited

Good intro!

A couple of things:

  • checkout iterm2.com/ when you have some spare time. I think it's better than the default OSX Terminal

  • if you work on computer you own you don't really need your name and computer's name in the prompt, this way you can save some room in the window

Collapse
 
clickclickonsal profile image
Sal Hernandez

Thank you. Actually that terminal was iterm2! I'm a huge fan of it! :-)

Bullet point 2 is a really good tip. I think I'll do that now because you're right! Freeing up real estate on the terminal is a plus!!!

Collapse
 
rjpsyco009 profile image
Ryan Norton

Took a UNIX class last December. I have to say, I wish I had kept more notes, but this was a lovely refresher to terminal! Thanks!

Collapse
 
clickclickonsal profile image
Sal Hernandez

I'm glad it helped! 😁

Collapse
 
fulopm profile image
Márk Fülöp • Edited

Great article!

How did you make your terminal prompt look this way? It looks very familiar, but I can't remember where did I see this.

Collapse
 
clickclickonsal profile image
Sal Hernandez
Collapse
 
fulopm profile image
Márk Fülöp • Edited

Cool, thank you!

Collapse
 
mrm8488 profile image
Manuel Romero

I use a lot
du -sh */ | sort -h
To order current folder files by size

Collapse
 
clickclickonsal profile image
Sal Hernandez

The -h flag comes invalid (I'm on a Mac). Thanks for that tip though! This is pretty cool!

Collapse
 
jgaskins profile image
Jamie Gaskins

They might've been going for sort -n instead. It sorts numerically instead of alphabetically (the only reasonable sort for du output). :-)

Collapse
 
mrm8488 profile image
Manuel Romero

Another fast tip for
ls command
ls -l --sort <time | size>

Collapse
 
dmn1k_13 profile image
Dominik Schlosser

ls -lrt sorts by time ascending so the file edited last is at the bottom.

Collapse
 
poison_dv profile image
David Virtser

Try sudo !! when you forgot to put sudo in front of last command.

Collapse
 
clickclickonsal profile image
Sal Hernandez

True! This is a good & powerful command. I'd like to mention that always understand what it is you're trying to do when you're using sudo. :-)