Terminal commands worth remembering
A running list of shell one-liners that are easy to forget and handy to have.
A cheat sheet that will keep growing. Everything here works in Bash on most Linux distributions.
Files#
# Biggest things in the current directory
du -sh * | sort -rh | head
# Files changed in the last day
find . -type f -mtime -1
# Copy a folder somewhere else, with a progress bar
rsync -ah --info=progress2 src/ dest/
Searching#
# Search recursively, with line numbers
grep -rn "TODO" .
# The same, but much faster and it respects .gitignore
rg "TODO"
Processes#
| Command | What it does |
|---|---|
htop |
Interactive process viewer |
ps aux --sort=-%mem | head |
Top memory users |
kill -9 <pid> |
Stop a process that won't stop |
lsof -i :8080 |
What's using port 8080? |
Networking#
# What's my public IP?
curl ifconfig.me
# Which ports are listening?
ss -tulpn
# Follow a log file as it grows
tail -f /var/log/syslog
History tricks#
!!repeats the last command, sosudo !!reruns it as root- Ctrl+R searches back through your history
cd -jumps back to the previous directory