Command line cheat sheet

Commands

Navigation commands

cd Change the current working directory.
pwd Print the current working directory.

File commands

ls List files
cp Copy a file
mv Move a file
rm Remove a file
touch Create an empty file. Change the modification date of an existing file.

Directory commands

mkdir Make a directory
rmdir Remove an empty directory
rm -r Remove a directory and all its contents

Miscelaneous commands

echo Print arguments
cat Print the contents of a file (or it’s input)
date Print the current date and time
wc Count words (and lines and characters) in file or input
tee Copy input to a file and print it
grep Print lines from input that match a regular expression

File names

Special names

. The current directory
.. The parent of the current directory
/ The root of the file system
~ Current user’s home directory

Globs

* Match any part of a file name (excludes hidden files)
.* Hidden files
** Any directory, recursively. Requires shopt -s globstar
? Any single character

Input/Output redirection

> Redirect output of program into file.)
>> Redirect output of program into file, appending.)
< Redirect contents of file into program as input.)
| Make the output of one program into the input of another program.)

Important environment variables

$PATH Colon-delimited list of directories to look for programs in.)
$PS1 Shell prompt.)
$CDPATH Colon-delimited list of directories to look for directories to cd into.)

Other commands to change the running shell

shopt Set shell options)
alias Create a command line alias)
unalias Remove an alias)
VAR=value Set the variable VAR to value.)
export VAR Make VAR in inherited environment variable.)

Documentation

man Manual pages for Unix commands and libraries.
help Online help for built-in bash commands.
tldr Modern, crowd sourced man replacement.