15. Cheat Sheet
15.1 File Operations Quick Reference
| Operation | Command |
|---|---|
| List files | ls -lah |
| Change directory | cd /path |
| Show current directory | pwd |
| Create directory | mkdir -p dir/sub |
| Create file | touch file.txt |
| Copy | cp -r src/ dst/ |
| Move/Rename | mv old new |
| Delete | rm -rf dir/ |
| View file | cat / less / head -20 / tail -20 |
| Real-time view | tail -f logfile |
| Search files | find / -name "*.log" |
| Search text | grep -rn "keyword" /path/ |
| Create link | ln -s target linkname |
| View file type | file filename |
| Count lines | wc -l file |
15.2 Permissions & Users Quick Reference
| Operation | Command |
|---|---|
| Change permissions | chmod 755 file |
| Change owner | chown user:group file |
| Add user | sudo adduser username |
| Delete user | sudo userdel -r username |
| Add to group | sudo usermod -aG group user |
| View user info | id username |
| Switch user | su - username |
| Run with elevated privileges | sudo command |
15.3 Process Management Quick Reference
| Operation | Command |
|---|---|
| View all processes | ps aux |
| Real-time monitoring | top / htop |
| Kill process by name | killall name |
| Force kill process | kill -9 PID |
| Run in background | nohup cmd & |
| Service management | systemctl start/stop/status |
| View logs | journalctl -u service |
| View ports | ss -tulnp |
15.4 Network Quick Reference
| Operation | Command |
|---|---|
| View IP | ip addr / ifconfig |
| View routing | ip route |
| Test connectivity | ping host |
| DNS lookup | dig domain |
| HTTP request | curl url |
| Download file | wget url |
| View firewall | sudo ufw status |
| Trace route | traceroute host |
15.5 Disk Quick Reference
| Operation | Command |
|---|---|
| View disk space | df -hT |
| View directory size | du -sh dir/ |
| View partitions | lsblk / fdisk -l |
| Mount | mount /dev/sdb1 /mnt |
| Unmount | umount /mnt |
| View memory | free -h |
| View inodes | df -i |
15.6 Package Management Quick Reference
| Operation | APT (Debian/Ubuntu) | DNF (Fedora/RHEL) | Pacman (Arch) |
|---|---|---|---|
| Update index | apt update | dnf check-update | pacman -Sy |
| Upgrade all | apt upgrade | dnf upgrade | pacman -Syu |
| Install | apt install pkg | dnf install pkg | pacman -S pkg |
| Uninstall | apt remove pkg | dnf remove pkg | pacman -Rns pkg |
| Search | apt search keyword | dnf search keyword | pacman -Ss keyword |
| Clean cache | apt clean | dnf clean all | pacman -Sc |
15.7 Keyboard Shortcuts Quick Reference
| Shortcut | Function |
|---|---|
| Ctrl+C | Terminate current command |
| Ctrl+Z | Suspend current command (resume in background with bg) |
| Ctrl+D | Exit current Shell / send EOF |
| Ctrl+L | Clear screen (equivalent to clear) |
| Ctrl+A | Move to beginning of line |
| Ctrl+E | Move to end of line |
| Ctrl+R | Reverse search command history |
| Ctrl+W | Delete previous word |
| Ctrl+U | Delete to beginning of line |
| Ctrl+K | Delete to end of line |
| Tab | Auto-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.