Skip to content

15. Cheat Sheet ​

15.1 File Operations Quick Reference ​

OperationCommand
List filesls -lah
Change directorycd /path
Show current directorypwd
Create directorymkdir -p dir/sub
Create filetouch file.txt
Copycp -r src/ dst/
Move/Renamemv old new
Deleterm -rf dir/
View filecat / less / head -20 / tail -20
Real-time viewtail -f logfile
Search filesfind / -name "*.log"
Search textgrep -rn "keyword" /path/
Create linkln -s target linkname
View file typefile filename
Count lineswc -l file

15.2 Permissions & Users Quick Reference ​

OperationCommand
Change permissionschmod 755 file
Change ownerchown user:group file
Add usersudo adduser username
Delete usersudo userdel -r username
Add to groupsudo usermod -aG group user
View user infoid username
Switch usersu - username
Run with elevated privilegessudo command

15.3 Process Management Quick Reference ​

OperationCommand
View all processesps aux
Real-time monitoringtop / htop
Kill process by namekillall name
Force kill processkill -9 PID
Run in backgroundnohup cmd &
Service managementsystemctl start/stop/status
View logsjournalctl -u service
View portsss -tulnp

15.4 Network Quick Reference ​

OperationCommand
View IPip addr / ifconfig
View routingip route
Test connectivityping host
DNS lookupdig domain
HTTP requestcurl url
Download filewget url
View firewallsudo ufw status
Trace routetraceroute host

15.5 Disk Quick Reference ​

OperationCommand
View disk spacedf -hT
View directory sizedu -sh dir/
View partitionslsblk / fdisk -l
Mountmount /dev/sdb1 /mnt
Unmountumount /mnt
View memoryfree -h
View inodesdf -i

15.6 Package Management Quick Reference ​

OperationAPT (Debian/Ubuntu)DNF (Fedora/RHEL)Pacman (Arch)
Update indexapt updatednf check-updatepacman -Sy
Upgrade allapt upgradednf upgradepacman -Syu
Installapt install pkgdnf install pkgpacman -S pkg
Uninstallapt remove pkgdnf remove pkgpacman -Rns pkg
Searchapt search keyworddnf search keywordpacman -Ss keyword
Clean cacheapt cleandnf clean allpacman -Sc

15.7 Keyboard Shortcuts Quick Reference ​

ShortcutFunction
Ctrl+CTerminate current command
Ctrl+ZSuspend current command (resume in background with bg)
Ctrl+DExit current Shell / send EOF
Ctrl+LClear screen (equivalent to clear)
Ctrl+AMove to beginning of line
Ctrl+EMove to end of line
Ctrl+RReverse search command history
Ctrl+WDelete previous word
Ctrl+UDelete to beginning of line
Ctrl+KDelete to end of line
TabAuto-complete command/path
!!Repeat last command (commonly used with sudo !!)
!$Last argument of the previous command

15.8 Useful Tips ​

bash
# sudo !! — re-run the last command with sudo
$ apt update
Permission denied
$ sudo !!              # automatically becomes sudo apt update

# Command substitution — embed the output of one command inside another
echo "Today's date is $(date +%Y-%m-%d)"

# Brace expansion — batch operations
mkdir project_{01..10}
cp file.txt{,.bak}       # equivalent to cp file.txt file.txt.bak
mv file.{txt,md}         # equivalent to mv file.txt file.md

# Command history
history                   # view history
!42                      # execute the 42nd history command
history | grep "docker"   # search history

# Multiple command execution
cmd1 && cmd2             # cmd2 runs only if cmd1 succeeds
cmd1 || cmd2             # cmd2 runs only if cmd1 fails
cmd1 ; cmd2              # run sequentially regardless of result

# xargs — convert input into command arguments
find . -name "*.tmp" | xargs rm
cat urls.txt | xargs -I {} curl -O {}

# watch — periodically execute a command and refresh output
watch -n 2 'df -h'       # refresh disk usage every 2 seconds
watch -n 1 'ps aux | wc -l'  # monitor process count changes

# alias — set command aliases
alias ll='ls -lah'
alias ports='ss -tulnp'
alias meminfo='free -h && echo "" && ps aux --sort=-%mem | head -10'
# To make permanent, add to ~/.bashrc

📝 Note: 📝 Learning advice: Practice more — the command line is like riding a bike, no amount of tutorials can replace hands-on practice. Make good use of Tab: Tab auto-completion is your best friend. Make good use of man: if unsure about usage, type man command. Don't be afraid of mistakes: you can experiment freely in a virtual machine. Back up important data: rm has no recycle bin.