A compact reference for moving around, inspecting files and keeping an eye on processes in a Bash shell.
Files and directories
Command
What it does
ls -lah
Long list, hidden files, human-readable sizes
cd -
Go back to the previous directory
mkdir -p a/b/c
Create nested directories
cp -r src/ dst/
Copy a directory recursively
du -sh *
Size of each item in the current directory
df -h
Free disk space per filesystem
less file.log
Page through a file (/ to search, q to quit)
tail -f file.log
Follow a growing file
Permissions
Permissions are read (4), write (2) and execute (1) for user, group and others. Try the chmod calculator to see how they add up.
chmod 644 notes.txt # rw-r--r--
chmod 755 deploy.sh # rwxr-xr-x
chmod +x script.sh # add execute for everyone
chown alice:dev report.md # change owner and group
Searching
grep -rn "TODO" src/ # recursive, with line numbers
grep -i "error" app.log | wc -l # count matches, case-insensitive
find . -name "*.md" -mtime -7 # markdown files changed in 7 days
find . -type f -size +100M # large files
Processes
ps aux | grep python # find a process
top # live view (htop if installed)
kill 1234 # polite stop (SIGTERM)
kill -9 1234 # force stop, last resort
command & # run in background
jobs; fg %1 # list jobs, bring one back
Archives
Task
Command
Create .tar.gz
tar -czf out.tar.gz dir/
Extract .tar.gz
tar -xzf out.tar.gz
List contents
tar -tzf out.tar.gz
Zip / unzip
zip -r out.zip dir/ · unzip out.zip
Shell shortcuts
Ctrl+R — search command history
Ctrl+A / Ctrl+E — jump to line start / end
Ctrl+W — delete the previous word
!! — repeat the last command; !$ — last argument of it