0% found this document useful (0 votes)
41 views

01 CLI Cheatsheet White

This document provides a cheat sheet for common command line tasks and commands. It summarizes commands for navigating and listing directories and files, searching, copying, moving and deleting files, changing file permissions and ownership, working with processes, getting help, and directing command output. The cheat sheet is presented by Tower, a Git client software, to provide essential information for working from the command line.

Uploaded by

ribeiro2782
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

01 CLI Cheatsheet White

This document provides a cheat sheet for common command line tasks and commands. It summarizes commands for navigating and listing directories and files, searching, copying, moving and deleting files, changing file permissions and ownership, working with processes, getting help, and directing command output. The cheat sheet is presented by Tower, a Git client software, to provide essential information for working from the command line.

Uploaded by

ribeiro2782
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

COMMAND LINE CHEAT SHEET

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

DIRECTORIES FILES SEARCH


Display path of current working directory Delete <file> Find all files named <file> inside <dir>
$ pwd $ rm <file> (use wildcards [*] to search for parts of
filenames, e.g. "file.*")
Change directory to <directory> Delete <directory> $ find <dir> -name "<file>"
$ cd <directory> $ rm -r <directory>
Output all occurrences of <text> inside
Navigate to parent directory <file> (add -i for case-insensitivity)
Force-delete <file> (add -r to force-delete
$ cd .. a directory) $ grep "<text>" <file>
$ rm -f <file>
List directory contents Search for all files containing <text>
inside <dir>
$ ls Rename <file-old> to <file-new>
$ grep -rl "<text>" <dir>
List detailed directory contents, including $ mv <file-old> <file-new>
hidden files
Move <file> to <directory> (possibly
$ ls -la NETWORK
overwriting an existing file)
Create new directory named <directory> $ mv <file> <directory> Ping <host> and display status
$ mkdir <directory> $ ping <host>
Copy <file> to <directory> (possibly
overwriting an existing file)
Output whois information for <domain>
OUTPUT $ cp <file> <directory>
$ whois <domain>
Output the contents of <file> Copy <directory1> and its contents to
Download <file> (via HTTP[S] or FTP)
$ cat <file> <directory2> (possibly overwriting files
in an existing directory) $ curl -O <url/to/file>
Output the contents of <file> using $ cp -r <directory1> <directory2>
the less command (which supports Establish an SSH connection to <host>
pagination etc.) with user <username>
Update file access & modification time
$ less <file> (and create <file> if it doesn’t exist) $ ssh <username>@<host>
$ touch <file>
Output the first 10 lines of <file> Copy <file> to a remote <host>
$ head <file> $ scp <file>
<user>@<host>:/remote/path
PERMISSIONS
Direct the output of <cmd> into <file>
$ <cmd> > <file> Change permissions of <file> to 755
PROCESSES
$ chmod 755 <file>
Append the output of <cmd> to <file>
Output currently running processes
$ <cmd> >> <file> Change permissions of <directory> (and
its contents) to 600 $ ps ax
Direct the output of <cmd1> to <cmd2>
$ chmod -R 600 <directory> Display live information about currently
$ <cmd1> | <cmd2> running processes
Change ownership of <file> to <user> and $ top
Clear the command line window <group> (add -R to include a directory’s
$ clear contents) Quit process with ID <pid>
$ chown <user>:<group> <file> $ kill <pid>

30-day free trial available at


www.git-tower.com
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 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

30-day free trial available at


www.git-tower.com

You might also like