01 CLI Cheatsheet White
01 CLI Cheatsheet White
presented by Tower - the best Git client for Mac and Windows
On the command line, help is always at Various keyboard shortcuts can assist you File and directory paths can get long and
hand: you can either type man <command> when entering text: Hitting CTRL+A moves awkward. If you’re addressing a path inside
or <command> --help to receive detailed the caret to the beginning and CTRL+E of your home folder though, you can make
documentation about the command in to the end of the line. In a similar fashion, things easier by using the ~ character. So
question. CTRL+K deletes all characters after and instead of writing cd /Users/your-username/
CTRL+U all characters in front of the caret. projects/ , a simple cd ~/projects/ will do.
Pressing CTRL+L clears the screen (simi- And in case you should forget your user
FILE PERMISSIONS larly to the clear command). If you should name, whoami will remind you.
ever want to abort a running command,
On Unix systems, file permissions are set CTRL+C will cancel it.
using three digits: the first one representing OUTPUT WITH “LESS”
the permissions for the owning user, the
second one for its group, and the third one THE “TAB” KEY The less command can display and pagi-
for anyone else. nate output. This means that it only displays
Whenever entering paths and file names, one page full of content and then waits for
Add up the desired access rights for each the TAB key comes in very handy. It auto- your explicit instructions. You’ll know you
digit as following: completes what you’ve written, reducing have less in front of you if the last line of
typos quite efficiently. E.g. when you want your screen either shows the file’s name or
4 - access/read (r)
2 - modify/write (w) to switch to a different directory, you can just a colon (:) . Apart from the arrow keys,
1 - execute (x) either type every component of the path hitting SPACE will scroll one page forward,
by hand: b will scroll one page backward, and q
For example, 755 means “rwx” for owner $ cd ~/projects/acmedesign/docs/ will quit the less program.
and “rx” for both group and anyone. 740 …or use the TAB key (try this yourself):
represents “rwx” for owner, “r” for group $ cd ~/pr[TAB]ojects/
and no rights for other users. ac[TAB]medesign/d[TAB]ocs/ DIRECTING OUTPUT
In case your typed characters are ambigu-
ous (because “ac” could point to the “ac- The output of a command does not
COMBINING COMMANDS medesign” or the “actionscript” folder), the necessarily have to be printed to the
command line won’t be able to autocom- command line. Instead, you can decide to
If you plan to run a series of commands plete. In that case, you can hit TAB twice direct it to somewhere else. Using the >
after another, it might be useful to combine to view all possible matches and then type operator, for example, output can be direc-
them instead of waiting for each command a few more characters. ted to a file. The following command will
to finish before typing the next one. To do save the running processes to a text file in
so, simply separate the commands with a your home folder:
semicolon (;) on the same line. THE ARROW KEYS $ ps ax > ~/processes.txt
Additionally, it is possible to execute a It is also possible to pass output to another
command only if its predecessor produces The command line keeps a history of the command using the | (pipe) operator,
a certain result. Code placed after the && most recent commands you executed. By which makes it very easy to create complex
operator will only be run if the previous pressing the ARROW UP key, you can step operations. E.g., this chain of commands
command completes successfully, while through the last called commands (starting will list the current directory’s contents,
the opposite || operator only continues if with the most recent). ARROW DOWN will search the list for PDF files and display the
the previous command fails. The following move forward in history towards the most results with the less command:
command will create the folder “videos” recent call. $ ls | grep ".pdf" | less
only if the cd command fails (and the fol- Bonus tip: Calling the history command
der therefore doesn’t exist): prints a list of all recent commands.
$ cd ~/videos || mkdir ~/videos