Now that you know some basic commands, we are going to learn some shortcuts.
I hope that learning these shortcuts serve us two purposes; first, after you learn them, shortcuts are going to save you some precious time while using the command line, and second, if you still don’t feel 100% comfortable while using the terminal, learning these shortcuts can help you overcome some of that command line resistance.
Alt + Tab: To try this shortcut, you should have only two programs open; your web browser with this page that you’re currently seeing and your terminal. Press this two keys and you should rapidly change between the two windows. The Alt + Tab shortcut let you switch between applications without using the mouse.
The history command: In your terminal type the command: “history” (without the double quotes) and press Enter. You should get a log of the commands you have recently typed.
Up/Down Arrows: Use the up and down arrows on your keyboard to quickly move through your last recent commands. You can press these shortcuts multiple times to navigate through your history and re-use one of the commands that you previously used.
Tab: This is one of everyone’s favorite shortcuts. While typing a file, directory, or command name, press Tab and your terminal will try to autocomplete what you were typing (if possible). If there is more than option to autocomplete, it will show you the various possible matches.
For example, let’s say you are in your home directory and you want to go to your Desktop; you could just type “cd De”, hit Tab to autocomplete the rest of the name of the directory and then press enter to change directories.
What would happen if you only type “cd D” and then press Tab? In my case, nothing happened.
Because I have more than one directory starting with the letter “D”, I have to press Tab twice so that the terminal can show me the matches I’ve got. The output at my terminal was:
Desktop/ Documents/ Downloads/
Showing me that I have three directories starting with “D”.
If I wanted to go the Downloads directory, I should type “cd Dow” + Tab, and then press enter to change directories while doing the minimum amount of keystrokes.
Ctrl + Shift + V: To paste text into the terminal, instead of using the classic Ctrl + V, you are going to need to add the Shift key for paste to function.
Paste this into your terminal:
the quick brown fox jumps over the lazy dog
So you can test the following shortcuts.
Ctrl+Left and Ctrl+Right: Hitting Ctrl and the left or right arrow keys jumps between words in your command line.
Ctrl+A or Home: Moves your cursor to the beginning of the line. This is useful if you’ve typed a command but realize that there’s a typo in the first word. Instead of holding down the left arrow key, just hit Ctrl+A or Home and correct it.
Ctrl+E or End: Moves your cursor to the end of the line.
Ctrl+W: This deletes the word before the cursor only.
Ctrl+U: This clears the entire line so you can type in a completely new command.
You can use the text from the previous lesson to try these shortcuts ;).
If you are in any directory different to your home directory, try typing only the “cd” command, without anything after it. This should take you to home fast and easy.
Ctrl+L: This “clears” the screen. And alternative is to run the “clear” command and press enter.
Ctrl+D: This closes the Terminal. And alternative is to type the “exit” command and press enter.
Ctrl + Alt + T: Press these three keys together and your terminal should appear automatically with your home directory as the path.
Right click + Open in Terminal: Right click on your desktop or on a random folder and click the option that says “Open in Terminal”, this should open your terminal with the path of the item that you “right-clicked”.
I really don’t own a mac, but the closest I got for a shortcut to quickly open the terminal is:
CMD + Space to open spotlight search, and then type in “terminal”.
Bring Cygwin to your desktop and use it from there.
If you haven’t been trying these shortcuts at your terminal, this is the moment to do so. Go through each shortcut and test it.
When you have finished testing and playing with each one of the ten lessons of shortcuts, go to the next page.