LINE CHEAT SHEET presented by TOWER — the most powerful Git client for Mac

DIRECTORIES FILES SEARCH

$ $ $

-name ""

Display path of current working directory Delete Find all files named inside

(use wildcards [*] to search for parts of $ $ rm -r filenames, e.g. "file.*") Change directory to Delete $ ""

$ cd .. $ rm -f Output all occurrences of inside (add -i for case-insensitivity) Navigate to parent directory Force-delete (add -r to force- delete a directory) $ grep -rl ""

$ Search for all files containing List directory contents $ inside Rename to $ ls -la List detailed directory contents, including $ mv NETWORK hidden files Move to (possibly overwriting an existing file) $ ping $ Ping and display status Create new directory named $ Copy to (possibly $ whois overwriting an existing file) OUTPUT Output whois information for $ cp -r $ curl -O $ Download (via HTTP[S] or FTP) Copy and its contents to Output the contents of (possibly overwriting files in an existing directory) $ ssh @ $ less Establish an SSH connection to Output the contents of using $ with user the less command (which supports pagination etc.) Update file access & modification (and create if it doesn’t exist) $ scp @:/remote/path $ Copy to a remote Output the first 10 lines of PERMISSIONS

$ > $ 755 PROCESSES Direct the output of into Change permissions of to 755 $ ax $ >> $ chmod -R 600 Output currently running processes Append the output of to Change permissions of (and $ top its contents) to 600 $ | Display live information about currently Direct the output of to $ : running processes Change ownership of to $ clear $ and (add -R to include a Clear the command line window directory’s contents) Quit process with ID

30-day free trial available www.git-tower.com the most powerful Git client for Mac COMMAND LINE TIPS & TRICKS presented by TOWER — the most powerful Git client for Mac

GETTING HELP THE “CTRL” KEY HOME FOLDER

On the command line, help is always at Various keyboard shortcuts can assist File and directory paths can get long hand: you can either man | you when entering text: Hitting CTRL+A| and awkward. If you’re addressing a or --help to receive detailed moves the caret to the beginning path inside of your home folder though, documentation about the command in and CTRL+E to the end of the line. you can things easier by using question. the ~ character. So instead of writing In a similar fashion, CTRL+K deletes cd /Users/your-username/projects/ , a all characters after and CTRL+U all simple cd ~/projects/ will do. FILE PERMISSIONS characters in front of the caret. Pressing CTRL+L clears the screen And in case you should forget your user On Unix systems, file permissions are (similarly to the clear command). If name, whoami will remind you. set using three digits: the first one you should ever want to abort a running representing the permissions for the command, CTRL+C will cancel it. owning user, the second one for its group, OUTPUT WITH “LESS” and the third one for anyone else. THE “TAB” KEY The less command can display and Add up the desired access rights for each paginate output. This means that it only digit as following: Whenever entering paths and file names, displays one page full of content and then the TAB key comes in very handy. It waits for your explicit instructions. You’ll 4 — access/read (r) autocompletes what you’ve written, know you have less in front of you if the 2 — modify/ (w) reducing typos quite efficiently. E.g. when last line of your screen either shows the 1 — execute (x) you want to switch to a different directory, file’s name or just a colon ( : ). For example, means “rwx” for owner you can either type every component of 755 Apart from the arrow keys, hitting SPACE| and “rx” for both group and anyone. the path by hand: 740| will scroll one page forward, b will scroll represents “rwx” for owner, “r” for group $ cd ~/projects/acmedesign/docs/ one page backward, and q will quit and no rights for other users. the program. …or use the TAB key (try this yourself): less

$ cd ~/pr[TAB]ojects/ COMBINING COMMANDS ac[TAB]medesign/d[TAB]ocs/ DIRECTING OUTPUT

If you plan to run a series of commands In case your typed characters are The output of a command does not after another, it might be useful to ambiguous (because “ac” could point to necessarily have to be printed to the combine them instead of waiting for each the “acmedesign” or the “actionscript” command line. Instead, you can decide to command to finish before typing the folder), the command line won’t be able direct it to somewhere else. next one. To do so, simply separate the to autocomplete. In that case, you can Using the > operator, for example, output commands with a semicolon ( ; ) on the hit TAB twice to view all possible matches can be directed to a file. The following same line. and then type a few characters. command will save the running processes Additionally, it is possble to execute a to a text file in your home folder: command only if its predecessor produces THE ARROW KEYS $ ps ax > ~/processes.txt a certain result. Code placed after the &&| The command line keeps a history of the operator will only be run if the previous It is also possible to pass output to another most recent commands you executed. By command completes successfully, while command using the | (pipe) operator, pressing the ARROW UP key, you can step the opposite operator only continues which makes it very easy to create complex || through the last called commands (starting if the previous command fails. The operations. E.g., this chain of commands with the most recent). ARROW DOWN will following command will create the folder will list the current directory’s contents, move forward in history towards the most “videos” only if the command fails search the list for PDF files and display the cd recent call. (and the folder therefore doesn’t exist): results with the less command: Bonus tip: Calling the history command $ cd ~/videos || mkdir ~/videos prints a list of all recent commands. $ ls | grep ".pdf" | less

30-day free trial available at www.git-tower.com the most powerful Git client for Mac