You are on page 1of 2

COMMAND LINE CHEAT SHEET

presented by Tower - the best Git client for Mac and Windows

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 doesn’t 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 directory’s contents) Quit process with ID <pid>

30-day free trial available at


www.git-tower.com The best Git Client for Mac & Windows
COMMAND LINE CHEAT SHEET
presented by Tower - the best Git client for Mac and Windows

GETTING HELP THE “CTRL” KEY HOME FOLDER


On the command line, help is always Various keyboard shortcuts can assist you File and directory paths can get long
at hand: you can either type  man when entering text: Hitting C
  TRL+A| moves and awkward. If you’re addressing a
<command>| or  <command> --help  to the caret to the beginning and  CTRL+E  to path inside of your home folder though,
receive detailed documentation about the the end of the line. you can make things easier by using
command in question. the  ~  character. So instead of writing
In a similar fashion,  CTRL+K  deletes all
 cd /Users/your-username/projects/ , a
characters after and C  TRL+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 you name,  whoami  will remind you.
set using three digits: the first one 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. You’ll
    — access/read (r)
4 autocompletes what you’ve written, know you have  less  in 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, file’s name or just a colon ( :)  .
For example,  755  means “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 the l ess 
and no rights for other users. 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 won’t be able direct it to somewhere else.
next one. To do so, simply separate the to autocomplete. In that case, you can
hit  TAB  twice 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 if which makes it very easy to create complex
through the last called commands (starting
the previous command fails. The following operations. E.g., this chain of commands
with the most recent).  ARROW DOWN  will
command will create the folder “videos” will list the current directory’s contents,
move forward in history towards the most
only if the  cd  command fails (and the search the list for PDF files and display the
recent call.
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 best Git Client for Mac & Windows

You might also like