Command line cheat sheet
The 109 commands and shell ideas you will use most, on one page. The everyday ones come first. Print it, or keep it open beside your editor.
Everyday 86
$- Put before a name to use a variable's value, as in $HOME.
$1- The first word typed after a script's name.
$PATH- The list of folders the shell checks, in order, for commands.
*- Matches any run of characters in a file name.
--help- Prints a short summary of a command's options.
-n- Sets how many lines head or tail prints, as in tail -n 3.
./script.sh- Runs a script in the current folder; it needs execute permission.
.bashrc- A file of shell commands run each time a new terminal starts.
2>- Saves error messages into a file.
644- Owner can read and write; everyone else can read. Usual for web files.
755- Owner can do everything; others can read and enter. Usual for folders.
>- Saves output into a file, replacing what was there.
>>- Adds output to the end of a file.
?- Matches exactly one character in a file name.
absolute path- A path starting with / that names the full route from the top.
alias- Makes a short name stand for a longer command.
cat- Prints a whole file in the terminal.
cd- Changes the folder you are working in.
cd ..- Moves up one level, to the parent folder.
chmod- Changes a file's permissions.
chmod +x- Lets a file be run as a program.
cp- Copies a file to a new name or folder.
cp -r- Copies a folder and everything inside it.
Ctrl+C- Stops the program running in the terminal in front of you.
cut -d -f- Keeps chosen fields, with -d naming the separator and -f the field numbers.
dot file- A file or folder whose name starts with a dot, hidden from plain ls.
echo- Prints its words, handy for previewing what a wildcard matches.
environment variable- A named value the shell keeps and passes to programs.
exit- Closes the ssh connection and returns you to your own computer.
export- Passes a variable on to programs started from this shell.
find- Searches a folder and all folders inside it for matching files.
find -delete- Deletes every match; run the search without it first.
find -name- Matches file names against a pattern, such as "*.bak".
for loop- Repeats the lines between do and done once for each item in a list.
grep- Prints the lines of a file that contain a pattern.
grep -i- Searches without caring about capital letters.
grep -n- Adds the line number to each match.
grep -r- Searches every file inside a folder.
head- Prints the first lines of a file, 10 unless you say otherwise.
kill- Sends a process a signal asking it to finish.
less- Opens a long file in a scrolling viewer; press q to leave.
ls- Lists the files and folders in the current folder, or a folder you name.
ls -a- Lists hidden names too, the ones that start with a dot.
ls -l- Shows one item per row with permissions, owner, size and date.
man- Opens the full manual page for a command.
mkdir- Makes a new folder.
mkdir -p- Makes a folder and any missing parent folders along the path.
mv- Moves or renames a file or folder.
PID- The process ID, the number used to point at one process.
pipeline- A chain of commands joined by pipes, built one stage at a time.
process- A program while it is running, with its own number.
prompt- The text before the cursor showing your user, computer and folder.
ps aux- Lists every running process with its CPU and memory use.
pwd- Prints the full path of the folder you are in.
relative path- A path that starts from the folder you are in.
rm- Deletes files at once, with no trash to restore them from.
rm -r- Deletes a folder and everything inside it.
rm -rf- Deletes folders and contents with no questions; check every name first.
rmdir- Removes a folder only if it is empty.
rwx- Read, write and execute, shown for owner, group and others in ls -l.
scp- Copies files between computers; server paths start with name and colon.
sed -i- Saves sed's change back into the file.
sed s///- Replaces text, as in sed 's/old/new/g' file.
shebang- The first line starting with #! that names the program to run the file.
shell- The program that reads what you type and runs it, usually bash.
shell script- A text file of commands bash runs from top to bottom.
sort- Prints lines in order, alphabetical by default.
sort -n- Sorts by numeric value, so 10 comes after 9.
sort -r- Reverses the sort order.
source- Runs a file in the current shell, often to reload .bashrc.
ssh- Logs in to another computer and gives you a prompt there.
tail- Prints the last lines of a file, 10 unless you say otherwise.
tar -czf- Packs files into a compressed .tar.gz archive.
tar -tzf- Lists what is inside a .tar.gz without unpacking it.
tar -xzf- Unpacks a .tar.gz archive.
terminal- The window where you type commands and read the replies.
touch- Makes an empty file, or updates the date on an existing one.
uniq- Collapses repeated neighbouring lines into one.
uniq -c- Prints how many times each line repeated; sort first.
unzip- Unpacks a .zip file; -l lists its contents.
wc -l- Counts the lines in a file or in piped text.
which- Prints the full path of the program a name would run.
working directory- The folder your commands run in unless you name another.
zip -r- Packs a folder into a .zip file.
|- Sends the output of one command into the next as its input.
~- Short for your home folder, such as /home/you.
Also useful 23
&- Runs a command in the background and gives you the prompt back.
2>&1- Sends error messages to the same place as normal output.
cd -- Goes back to the folder you were in before the last cd.
env- Lists every exported variable.
find -iname- Like -name but ignores capital letters.
find -type- Keeps only files (f) or only folders (d).
grep -c- Counts the matching lines in each file.
grep -l- Prints only the names of files with a match.
grep -v- Prints the lines that do not match.
kill -9- Forces a process to stop without a chance to clean up.
ls -h- Shows sizes as K, M or G, used with -l.
ls -S- Sorts the list with the largest files first.
nano- A small text editor that runs inside the terminal.
Permission denied- The message you get when your account lacks the right permission.
quotes around names- Wrap a name with spaces in quotes so the shell reads it as one.
rm -f- Deletes without asking and without complaining about missing files.
rm -i- Asks before deleting each file.
sed /pattern/d- Deletes each line that contains the pattern.
sort -t -k- Sorts by one field, with -t naming the separator and -k the field.
ssh-keygen- Makes a key pair so you can log in without typing a password.
Tab completion- Press Tab after a few letters and the shell finishes the name for you.
tail -f- Keeps printing new lines as they are added to a log.
tee- Shows output on screen and saves it to a file at once.
PlainFinch Command line cheat sheet · plainfinch.com/cli/cheat-sheet/ · version 3.25.2