// REF. 02 / SHELL
Command line cheat sheet
The terminal commands you’ll reach for every day, from moving around and reading files to pipes, processes and the shortcuts that make the prompt faster. Everything here works in bash and zsh on macOS and Linux.
Two habits pay off fast: Ctrl-r to search your history instead of retyping, and | to chain small commands into big ones. Every command on this page is printed on our Command Line Field Manual desk mat.
↓ Download the printable PDF free · letter size · no email needed
Navigate
pwd- where am I
ls -la- list all, long format
cd -- previous directory
cd ~- home directory
Files
cp -r a b- copy recursively
mv a b- move / rename
rm -r dir- remove directory
mkdir -p a/b/c- make nested dirs
touch f- create empty file
ln -s target link- symlink
Read
cat f- print file
less f- page through file
head -n 20 f- first 20 lines
tail -f log- follow a log
wc -l f- count lines
Find
grep -rn "x" .- search text, with line no.
find . -name "*.js"- find files by name
which cmd- where a command lives
history | grep ssh- search past commands
Pipes & redirects
a | b- pipe a into b
> f- write to file
>> f- append to file
2>&1- stderr into stdout
< f- read input from file
$(cmd)- command substitution
Processes
ps aux- list processes
top- live process view
kill PID- stop a process
cmd &- run in background
jobs / fg / bg- manage jobs
Ctrl-c / Ctrl-z- interrupt / suspend
Network
curl -I url- fetch headers
ssh user@host- remote shell
scp f host:dir- copy over ssh
lsof -i :3000- who's on port 3000
Permissions
chmod +x f- make executable
chmod 644 f- rw-r--r--
chown user f- change owner
sudo !!- last command, as root
Line editing
Ctrl-a / Ctrl-e- start / end of line
Ctrl-r- search history
Ctrl-w- delete word back
Ctrl-l- clear screen
!! / !$- last command / last arg
Tab- complete
// KEEP IT UNDER YOUR KEYBOARD
Command Line Field Manual Desk Mat
from $34 · printed to order in the USA