I’ve spent years bouncing between servers, VMs, and my own laptop, and if there’s one skill that has never stopped paying off, it’s knowing my way around the Linux terminal. I put together this cheat sheet as the reference I wish I’d had when I started — the kind of thing I now keep bookmarked and actually use, not some list I skimmed once and forgot.
Whether I’m debugging a production server at 2 AM, setting up a fresh Ubuntu box, or just trying to remember the flag for tar (again), this is the guide I reach for. I’ve organized it into quick-reference sections so you can jump straight to what you need.
Table of Contents
- File & Directory Navigation
- File Operations
- Viewing & Editing Files
- Permissions & Ownership
- Process Management
- Networking Commands
- Disk & Storage Management
- User & Group Management
- Package Management
- Archiving & Compression
- System Monitoring
- Searching & Filtering
- Keyboard Shortcuts & Productivity Tricks
- Best Practices
- Troubleshooting Common Issues
- Security Tips
- Real-World Workflows
- FAQs
- Interview Questions
- Common Mistakes
- Printable Quick-Reference Summary
- Official Documentation Links
1. File & Directory Navigation
Navigation is the first thing I learned and the thing I still do hundreds of times a day.
| Command | Description | Example |
|---|---|---|
pwd | Print current working directory | pwd → /home/user/projects |
ls | List directory contents | ls -la |
cd | Change directory | cd /var/log |
cd .. | Move up one directory | cd .. |
cd ~ | Go to home directory | cd ~ |
cd - | Go to previous directory | cd - |
tree | Show directory structure as a tree | tree -L 2 |
find | Locate files/directories | find . -name "*.log" |
Common ls flags I use constantly:
-l— long listing format (permissions, owner, size, date)-a— show hidden files (dotfiles)-h— human-readable sizes (KB, MB, GB)-t— sort by modification time-S— sort by file size-R— recursive listing
Example output:
$ ls -lh
-rw-r--r-- 1 user user 4.2K Jul 12 10:22 notes.txt
drwxr-xr-x 3 user user 4.0K Jul 10 08:15 projects
I use cd - all the time when I’m bouncing between two directories — it toggles you back to wherever you just were.
2. File Operations
| Command | Description | Example |
|---|---|---|
touch | Create an empty file | touch newfile.txt |
mkdir | Create a directory | mkdir -p project/src/utils |
cp | Copy files/directories | cp -r src/ backup/ |
mv | Move or rename files | mv old.txt new.txt |
rm | Remove files/directories | rm -rf old_build/ |
rmdir | Remove empty directory | rmdir empty_folder |
ln | Create links | ln -s /path/to/file linkname |
stat | Show detailed file metadata | stat file.txt |
A habit I picked up early: always use mkdir -p when creating nested directories, so I don’t get an error if a parent folder doesn’t exist yet.
mkdir -p ~/projects/app/src/components
For symbolic links, ln -s is the one I use almost exclusively — hard links (ln without -s) have quirks around filesystems and inodes that trip people up.
3. Viewing & Editing Files
| Command | Description | Example |
|---|---|---|
cat | Print file contents | cat config.yml |
less | Page through a file | less bigfile.log |
more | Simple pager (older) | more file.txt |
head | Show first N lines | head -n 20 access.log |
tail | Show last N lines | tail -f app.log |
nano | Beginner-friendly editor | nano config.txt |
vim | Powerful modal editor | vim script.sh |
diff | Compare two files | diff file1.txt file2.txt |
tail -f is one I use constantly when I want to watch a log file update live:
tail -f /var/log/nginx/error.log
If I need to watch multiple files at once, I’ll add them side by side:
tail -f app.log error.log
4. Permissions & Ownership
Linux permissions confuse a lot of newcomers, so I’ll break it down the way I explain it to people I mentor.
Every file has three permission sets: owner, group, and others. Each can have read (r), write (w), and execute (x).
| Symbol | Numeric | Meaning |
|---|---|---|
r | 4 | Read |
w | 2 | Write |
x | 1 | Execute |
- | 0 | No permission |
| Command | Description | Example |
|---|---|---|
chmod | Change file permissions | chmod 755 script.sh |
chown | Change file owner | chown user:group file.txt |
chgrp | Change group ownership | chgrp devs file.txt |
umask | Set default permission mask | umask 022 |
Common permission combos I use:
chmod 644 file.txt # rw-r--r-- (standard file)
chmod 755 script.sh # rwxr-xr-x (executable script)
chmod 600 id_rsa # rw------- (private SSH key)
I always run chmod 600 on private keys — SSH will actually refuse to use a key with looser permissions, and it’s a quick thing to forget.
5. Process Management
| Command | Description | Example |
|---|---|---|
ps | Show running processes | ps aux |
top | Live process monitor | top |
htop | Improved interactive monitor | htop |
kill | Terminate a process by PID | kill 1234 |
killall | Kill by process name | killall node |
bg | Resume a job in background | bg %1 |
fg | Bring job to foreground | fg %1 |
jobs | List background jobs | jobs |
nohup | Run immune to hangups | nohup ./script.sh & |
nice / renice | Adjust process priority | nice -n 10 ./task.sh |
When a process won’t die with a normal kill, I escalate:
kill -15 1234 # SIGTERM - polite request to stop
kill -9 1234 # SIGKILL - forceful, no cleanup
I try -15 first because it lets the process clean up (close file handles, save state). -9 is my last resort.
6. Networking Commands
| Command | Description | Example |
|---|---|---|
ping | Test connectivity | ping google.com |
curl | Transfer data from/to a server | curl -I https://example.com |
wget | Download files | wget https://site.com/file.zip |
ssh | Secure remote login | ssh user@server.com |
scp | Secure copy over SSH | scp file.txt user@server:/path |
netstat | Network connections (legacy) | netstat -tulpn |
ss | Modern socket statistics | ss -tulpn |
ip a | Show IP addresses | ip a |
dig | DNS lookup | dig example.com |
traceroute | Trace network path | traceroute example.com |
I use ss -tulpn far more than netstat these days since most modern distros have moved on from net-tools.
ss -tulpn | grep :80
That instantly tells me what’s listening on port 80.
7. Disk & Storage Management
| Command | Description | Example |
|---|---|---|
df | Disk space usage | df -h |
du | Directory/file size | du -sh /var/log |
mount | Mount a filesystem | mount /dev/sdb1 /mnt/data |
umount | Unmount a filesystem | umount /mnt/data |
lsblk | List block devices | lsblk |
fdisk | Partition management | fdisk -l |
fsck | Check/repair filesystem | fsck /dev/sda1 |
When a server is running low on space, my go-to combo is:
du -sh /* 2>/dev/null | sort -rh | head -10
That sorts top-level directories by size, largest first, so I can immediately see what’s eating disk space.
8. User & Group Management
| Command | Description | Example |
|---|---|---|
useradd | Create a new user | useradd -m john |
usermod | Modify a user | usermod -aG sudo john |
userdel | Delete a user | userdel -r john |
passwd | Change password | passwd john |
groupadd | Create a group | groupadd developers |
groups | Show group membership | groups john |
whoami | Show current user | whoami |
su | Switch user | su - john |
sudo | Run as another user (root) | sudo systemctl restart nginx |
Adding a user to the sudo group is one I do often on fresh servers:
usermod -aG sudo john
The -a (append) flag matters here — without it, usermod -G overwrites all existing group memberships instead of adding to them. That’s a mistake I made exactly once.
9. Package Management
Since distros differ, here’s a side-by-side.
| Task | Debian/Ubuntu (apt) | RHEL/CentOS/Fedora (dnf/yum) |
|---|---|---|
| Update package list | sudo apt update | sudo dnf check-update |
| Upgrade packages | sudo apt upgrade | sudo dnf upgrade |
| Install package | sudo apt install nginx | sudo dnf install nginx |
| Remove package | sudo apt remove nginx | sudo dnf remove nginx |
| Search package | apt search nginx | dnf search nginx |
| List installed | apt list --installed | dnf list installed |
| Clean cache | sudo apt autoremove | sudo dnf autoremove |
I always run apt update before apt upgrade — skipping it means you might be installing based on a stale package index.
10. Archiving & Compression
| Command | Description | Example |
|---|---|---|
tar -cvf | Create a tar archive | tar -cvf backup.tar folder/ |
tar -xvf | Extract a tar archive | tar -xvf backup.tar |
tar -czvf | Create gzip-compressed tar | tar -czvf backup.tar.gz folder/ |
tar -xzvf | Extract gzip tar | tar -xzvf backup.tar.gz |
zip | Create zip archive | zip -r archive.zip folder/ |
unzip | Extract zip archive | unzip archive.zip |
gzip / gunzip | Compress/decompress single file | gzip file.txt |
I still mix up tar flags occasionally, so I keep this mnemonic in my head: create, extract, z for gzip, v for verbose, f for filename (always last).
tar -czvf project_backup.tar.gz /home/user/project
11. System Monitoring
| Command | Description | Example |
|---|---|---|
uptime | Show system uptime and load | uptime |
free | Memory usage | free -h |
vmstat | Virtual memory stats | vmstat 2 5 |
iostat | CPU and I/O stats | iostat -x 2 |
dmesg | Kernel ring buffer messages | `dmesg |
journalctl | View systemd logs | journalctl -u nginx -f |
uname -a | Kernel and system info | uname -a |
When something feels slow, my first three commands, in order, are always uptime, free -h, and top. That gives me load average, memory pressure, and a live view of what’s consuming resources.
12. Searching & Filtering
| Command | Description | Example |
|---|---|---|
grep | Search text patterns | grep -r "ERROR" /var/log/ |
find | Search files by criteria | find / -name "*.conf" -mtime -7 |
locate | Fast filename search (indexed) | locate nginx.conf |
awk | Pattern scanning & text processing | awk '{print $1}' file.txt |
sed | Stream editor for text transforms | sed 's/foo/bar/g' file.txt |
xargs | Build commands from input | `find . -name “*.tmp” |
wc | Word/line/byte count | wc -l file.txt |
A search-and-cleanup combo I use often:
find . -name "*.log" -mtime +30 | xargs rm -f
That deletes log files older than 30 days. I always test with find ... -print first before piping to rm, because there’s no undo.
13. Keyboard Shortcuts & Productivity Tricks
| Shortcut | Action |
|---|---|
Ctrl + C | Kill current command |
Ctrl + Z | Suspend current command |
Ctrl + D | Exit shell / send EOF |
Ctrl + R | Reverse search command history |
Ctrl + L | Clear terminal screen |
Ctrl + A / Ctrl + E | Jump to start/end of line |
Tab | Auto-complete |
!! | Repeat last command |
!$ | Last argument of previous command |
history | Show command history |
Ctrl + R followed by typing a fragment of a command I ran last week is something I use dozens of times a day — it’s saved me more typing than any other habit on this list.
14. Best Practices
- Always double-check destructive commands (
rm -rf,dd) before hitting enter — I read the full command left to right one more time. - Use
history | grepto find how I solved something before. - Alias frequent commands in
~/.bashrcor~/.zshrc— I havealias ll='ls -lah'on every machine I touch. - Prefer
rsyncovercpfor large or remote transfers — it resumes and only copies changes. - Keep scripts under version control, even personal ones.
- Use
screenortmuxfor long-running remote sessions so a dropped connection doesn’t kill your work.
15. Troubleshooting Common Issues
“Permission denied” when running a script Check execute permission: ls -l script.sh, then chmod +x script.sh.
“No space left on device” but df shows free space You may be out of inodes, not blocks: df -i.
A process won’t stop Escalate from SIGTERM to SIGKILL: kill -15 PID then kill -9 PID.
SSH connection refused Check the SSH service is running (systemctl status sshd) and the port isn’t blocked by a firewall (ss -tulpn | grep 22).
Command not found after installing something Check your PATH: echo $PATH, and confirm the binary’s location with which or type.
16. Security Tips
- Never run commands as root unless you have to — use
sudofor individual actions instead ofsudo -isessions. - Lock down SSH key permissions with
chmod 600. - Disable password-based root login over SSH; use key-based auth instead.
- Regularly audit
lastandwhoto see who has logged in. - Use
ufworfirewalldto restrict open ports to only what’s needed. - Keep systems patched with regular
apt upgrade/dnf upgradecycles. - Avoid piping untrusted scripts directly into
bash(curl url | bash) without reading them first.
17. Real-World Workflows
Deploying a quick fix to a live server:
ssh user@server.com
cd /var/www/app
git pull origin main
sudo systemctl restart app
journalctl -u app -f
Finding what’s eating disk space on a full server:
df -h
du -sh /var/* 2>/dev/null | sort -rh | head -10
Backing up a directory before a risky change:
tar -czvf backup_$(date +%F).tar.gz /etc/nginx
Watching logs while reproducing a bug:
tail -f /var/log/app/error.log &
curl -X POST http://localhost:3000/api/test
18. FAQs
What’s the difference between sudo and su? sudo runs a single command with elevated privileges and asks for your own password; su switches you to another user’s shell entirely (often root) and asks for that user’s password.
How do I find which process is using a specific port? ss -tulpn | grep :PORT or lsof -i :PORT.
What does chmod 755 actually mean? Owner gets read/write/execute (7), group gets read/execute (5), others get read/execute (5).
How do I safely delete files without accidentally nuking the wrong folder? Run the find part alone first, review the output, then pipe to xargs rm only once you’re confident.
Is nano or vim better for beginners? nano is friendlier for people just starting out — the commands are shown on-screen. vim has a steeper learning curve but is far more powerful once it clicks.
19. Interview Questions
- Explain the difference between a hard link and a symbolic link.
- What happens when you run
kill -9on a process versuskill -15? - How would you find all files larger than 100MB in
/var? - Walk through what each part of
chmod 750means. - What’s the difference between
>and>>in redirection? - How do you check which services are listening on which ports?
- Explain the boot process at a high level (BIOS/UEFI → bootloader → kernel → init).
- What’s the difference between
aptanddpkg? - How would you troubleshoot a server that suddenly has 100% CPU usage?
- What does the sticky bit do, and where is it commonly used?
20. Common Mistakes
- Running
rm -rfwith a space in the wrong place (rm -rf / home/userinstead ofrm -rf /home/user) — always double-check spacing. - Forgetting
-aonusermod -G, which wipes existing group memberships. - Using
kill -9as a first resort instead of a last one. - Editing config files directly on production without a backup copy first.
- Confusing
>(overwrite) with>>(append) when redirecting output. - Assuming
locateresults are current — its database only updates periodically (updatedb). - Forgetting that
chmod -Rapplies recursively, which can loosen permissions on files you didn’t intend to touch.
21. Printable Quick-Reference Summary
NAVIGATION pwd, ls -la, cd, tree
FILES touch, mkdir -p, cp -r, mv, rm -rf
VIEW/EDIT cat, less, head, tail -f, nano, vim
PERMISSIONS chmod 755, chown user:group, umask
PROCESSES ps aux, top, htop, kill -15/-9
NETWORK ping, curl -I, ssh, scp, ss -tulpn
DISK df -h, du -sh, lsblk, mount
USERS useradd -m, usermod -aG, passwd
PACKAGES apt update && apt upgrade | dnf upgrade
ARCHIVE tar -czvf archive.tar.gz folder/
MONITOR uptime, free -h, journalctl -u service -f
SEARCH grep -r, find -name, awk, sed
SHORTCUTS Ctrl+R, Ctrl+L, !!, !$
22. Official Documentation Links
- GNU Coreutils Manual
- The Linux man-pages project
- Ubuntu Server Documentation
- Red Hat Enterprise Linux Documentation
- Arch Wiki (excellent even for non-Arch users)
That’s the full cheat sheet as I use it day to day. Bookmark it, keep it open in a tab, and if you’re anything like me, you’ll still learn a new flag on a command you’ve run a thousand times.