You are on page 1of 2

COMMAND LINE CHEAT SHEET

presented by TOWER Version control with Git - made easy

DIRECTORIES FILES SEARCH


$ pwd $ rm <file> $ find <dir> -name "<file>"

Display path of current working directory Delete <file> Find all files named <file> inside <dir>
(use wildcards [*] to search for parts of
$ cd <directory> $ rm -r <directory> filenames, e.g. "file.*")
Change directory to <directory> Delete <directory> $ grep "<text>" <file>

$ cd .. $ rm -f <file> Output all occurrences of <text> inside


<file> (add -i for case-insensitivity)
Navigate to parent directory Force-delete <file> (add -r to force-
delete a directory) $ grep -rl "<text>" <dir>
$ ls
$ mv <file-old> <file-new> Search for all files containing <text>
List directory contents inside <dir>
Rename <file-old> to <file-new>
$ ls -la

List detailed directory contents, including $ mv <file> <directory> NETWORK


hidden files Move <file> to <directory> (possibly
overwriting an existing file) $ ping <host>
$ mkdir <directory>
$ cp <file> <directory> Ping <host> and display status
Create new directory named <directory>
Copy <file> to <directory> (possibly $ whois <domain>
overwriting an existing file)
Output whois information for <domain>
OUTPUT
$ cp -r <directory1>
<directory2> $ curl -O <url/to/file>
$ cat <file>
Copy <directory1> and its contents to Download <file> (via HTTP[S] or FTP)
Output the contents of <file>
<directory2> (possibly overwriting files
in an existing directory) $ ssh <username>@<host>
$ less <file>
Establish an SSH connection to <host>
Output the contents of <file> using $ touch <file> with user <username>
the less command (which supports
pagination etc.) Update file access & modification time
(and create <file> if it doesnt exist) $ scp <file>
<user>@<host>:/remote/path
$ head <file>
Copy <file> to a remote <host>
Output the first 10 lines of <file> PERMISSIONS
$ <cmd> > <file> PROCESSES
$ chmod 755 <file>
Direct the output of <cmd> into <file>
Change permissions of <file> to 755
$ ps ax
$ <cmd> >> <file>
$ chmod -R 600 <directory> Output currently running processes
Append the output of <cmd> to <file>
Change permissions of <directory> (and $ top
its contents) to 600
$ <cmd1> | <cmd2>
Display live information about currently
Direct the output of <cmd1> to <cmd2> $ chown <user>:<group> <file> running processes

$ clear Change ownership of <file> to <user> $ kill <pid>


and <group> (add -R to include a
Clear the command line window directorys contents) Quit process with ID <pid>

30-day free trial available at


www.git-tower.com Version control with Git - made easy
COMMAND LINE TIPS & TRICKS

presented by TOWER Version control with Git - made easy

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 type man <command>| you when entering text: Hitting CTRL+A| and awkward. If youre addressing a
or <command> --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 make 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
characters in front of the caret. simple cd ~/projects/ will do.
FILE PERMISSIONS
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 less command can display and
THE TAB KEY
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. Youll
4 access/read (r) autocompletes what youve written, know you have lessin front of you if the
2 modify/write (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, files name or just a colon (:).
For example, 755means rwx for owner you can either type every component of
Apart from the arrow keys, hitting SPACE|
and rx for both group and anyone. 740| the path by hand:
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 less program.
or use the TAB key (try this yourself):
$ 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 wont be able direct it to somewhere else.
next one. To do so, simply separate the to autocomplete. In that case, you can
hit TABtwice to view all possible matches Using the >operator, for example, output
commands with a semicolon ( ;) on the
and then type a few more characters. can be directed to a file. The following
same line.
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). ARROWDOWN will
following command will create the folder will list the current directorys contents,
move forward in history towards the most
videos only if the cd command fails search the list for PDF files and display the
recent call.
(and the folder therefore doesnt exist): results with the less command:
Bonus tip: Calling the historycommand
$ 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 Version control with Git - made easy

You might also like