Ultimate Linux Commands Cheat Sheet: Essential Terminal Commands for Power Users

Ultimate Linux Commands Cheat Sheet

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

  1. File & Directory Navigation
  2. File Operations
  3. Viewing & Editing Files
  4. Permissions & Ownership
  5. Process Management
  6. Networking Commands
  7. Disk & Storage Management
  8. User & Group Management
  9. Package Management
  10. Archiving & Compression
  11. System Monitoring
  12. Searching & Filtering
  13. Keyboard Shortcuts & Productivity Tricks
  14. Best Practices
  15. Troubleshooting Common Issues
  16. Security Tips
  17. Real-World Workflows
  18. FAQs
  19. Interview Questions
  20. Common Mistakes
  21. Printable Quick-Reference Summary
  22. 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.

CommandDescriptionExample
pwdPrint current working directorypwd → /home/user/projects
lsList directory contentsls -la
cdChange directorycd /var/log
cd ..Move up one directorycd ..
cd ~Go to home directorycd ~
cd -Go to previous directorycd -
treeShow directory structure as a treetree -L 2
findLocate files/directoriesfind . -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

CommandDescriptionExample
touchCreate an empty filetouch newfile.txt
mkdirCreate a directorymkdir -p project/src/utils
cpCopy files/directoriescp -r src/ backup/
mvMove or rename filesmv old.txt new.txt
rmRemove files/directoriesrm -rf old_build/
rmdirRemove empty directoryrmdir empty_folder
lnCreate linksln -s /path/to/file linkname
statShow detailed file metadatastat 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

CommandDescriptionExample
catPrint file contentscat config.yml
lessPage through a fileless bigfile.log
moreSimple pager (older)more file.txt
headShow first N lineshead -n 20 access.log
tailShow last N linestail -f app.log
nanoBeginner-friendly editornano config.txt
vimPowerful modal editorvim script.sh
diffCompare two filesdiff 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).

SymbolNumericMeaning
r4Read
w2Write
x1Execute
-0No permission
CommandDescriptionExample
chmodChange file permissionschmod 755 script.sh
chownChange file ownerchown user:group file.txt
chgrpChange group ownershipchgrp devs file.txt
umaskSet default permission maskumask 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

CommandDescriptionExample
psShow running processesps aux
topLive process monitortop
htopImproved interactive monitorhtop
killTerminate a process by PIDkill 1234
killallKill by process namekillall node
bgResume a job in backgroundbg %1
fgBring job to foregroundfg %1
jobsList background jobsjobs
nohupRun immune to hangupsnohup ./script.sh &
nice / reniceAdjust process prioritynice -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

CommandDescriptionExample
pingTest connectivityping google.com
curlTransfer data from/to a servercurl -I https://example.com
wgetDownload fileswget https://site.com/file.zip
sshSecure remote loginssh user@server.com
scpSecure copy over SSHscp file.txt user@server:/path
netstatNetwork connections (legacy)netstat -tulpn
ssModern socket statisticsss -tulpn
ip aShow IP addressesip a
digDNS lookupdig example.com
tracerouteTrace network pathtraceroute 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

CommandDescriptionExample
dfDisk space usagedf -h
duDirectory/file sizedu -sh /var/log
mountMount a filesystemmount /dev/sdb1 /mnt/data
umountUnmount a filesystemumount /mnt/data
lsblkList block deviceslsblk
fdiskPartition managementfdisk -l
fsckCheck/repair filesystemfsck /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

CommandDescriptionExample
useraddCreate a new useruseradd -m john
usermodModify a userusermod -aG sudo john
userdelDelete a useruserdel -r john
passwdChange passwordpasswd john
groupaddCreate a groupgroupadd developers
groupsShow group membershipgroups john
whoamiShow current userwhoami
suSwitch usersu - john
sudoRun 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.

TaskDebian/Ubuntu (apt)RHEL/CentOS/Fedora (dnf/yum)
Update package listsudo apt updatesudo dnf check-update
Upgrade packagessudo apt upgradesudo dnf upgrade
Install packagesudo apt install nginxsudo dnf install nginx
Remove packagesudo apt remove nginxsudo dnf remove nginx
Search packageapt search nginxdnf search nginx
List installedapt list --installeddnf list installed
Clean cachesudo apt autoremovesudo 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

CommandDescriptionExample
tar -cvfCreate a tar archivetar -cvf backup.tar folder/
tar -xvfExtract a tar archivetar -xvf backup.tar
tar -czvfCreate gzip-compressed tartar -czvf backup.tar.gz folder/
tar -xzvfExtract gzip tartar -xzvf backup.tar.gz
zipCreate zip archivezip -r archive.zip folder/
unzipExtract zip archiveunzip archive.zip
gzip / gunzipCompress/decompress single filegzip 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

CommandDescriptionExample
uptimeShow system uptime and loaduptime
freeMemory usagefree -h
vmstatVirtual memory statsvmstat 2 5
iostatCPU and I/O statsiostat -x 2
dmesgKernel ring buffer messages`dmesg
journalctlView systemd logsjournalctl -u nginx -f
uname -aKernel and system infouname -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

CommandDescriptionExample
grepSearch text patternsgrep -r "ERROR" /var/log/
findSearch files by criteriafind / -name "*.conf" -mtime -7
locateFast filename search (indexed)locate nginx.conf
awkPattern scanning & text processingawk '{print $1}' file.txt
sedStream editor for text transformssed 's/foo/bar/g' file.txt
xargsBuild commands from input`find . -name “*.tmp”
wcWord/line/byte countwc -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

ShortcutAction
Ctrl + CKill current command
Ctrl + ZSuspend current command
Ctrl + DExit shell / send EOF
Ctrl + RReverse search command history
Ctrl + LClear terminal screen
Ctrl + A / Ctrl + EJump to start/end of line
TabAuto-complete
!!Repeat last command
!$Last argument of previous command
historyShow 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 | grep to find how I solved something before.
  • Alias frequent commands in ~/.bashrc or ~/.zshrc — I have alias ll='ls -lah' on every machine I touch.
  • Prefer rsync over cp for large or remote transfers — it resumes and only copies changes.
  • Keep scripts under version control, even personal ones.
  • Use screen or tmux for 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 sudo for individual actions instead of sudo -i sessions.
  • Lock down SSH key permissions with chmod 600.
  • Disable password-based root login over SSH; use key-based auth instead.
  • Regularly audit last and who to see who has logged in.
  • Use ufw or firewalld to restrict open ports to only what’s needed.
  • Keep systems patched with regular apt upgrade / dnf upgrade cycles.
  • 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

  1. Explain the difference between a hard link and a symbolic link.
  2. What happens when you run kill -9 on a process versus kill -15?
  3. How would you find all files larger than 100MB in /var?
  4. Walk through what each part of chmod 750 means.
  5. What’s the difference between > and >> in redirection?
  6. How do you check which services are listening on which ports?
  7. Explain the boot process at a high level (BIOS/UEFI → bootloader → kernel → init).
  8. What’s the difference between apt and dpkg?
  9. How would you troubleshoot a server that suddenly has 100% CPU usage?
  10. What does the sticky bit do, and where is it commonly used?

20. Common Mistakes

  • Running rm -rf with a space in the wrong place (rm -rf / home/user instead of rm -rf /home/user) — always double-check spacing.
  • Forgetting -a on usermod -G, which wipes existing group memberships.
  • Using kill -9 as 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 locate results are current — its database only updates periodically (updatedb).
  • Forgetting that chmod -R applies 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


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.

Total
3
Shares

Leave a Reply

Previous Post
Ultimate Git Lab Commands Cheat Sheet

Ultimate GitLab Commands Cheat Sheet: CI/CD, Repository, and DevOps Workflow Reference

Next Post
Ultimate MongoDB Commands Cheat Sheet

Ultimate MongoDB Commands Cheat Sheet: NoSQL Database Operations and Queries

Related Posts