Guide Linux All Levels

Linux Command Cheatsheet

A single-page, at-a-glance Linux command reference — files, permissions, processes, networking, text processing, disk, packages, archiving, and systemd — for fast lookup during work or interviews.

5 min read

A fast, scannable reference. For explanations and examples behind any of these, see the Linux Commands and Linux Fundamentals sections.

CommandDescription
pwdPrint current directory
cd -Go to previous directory
ls -laList all files, long format, including hidden
mkdir -p a/b/cCreate nested directories
cp -a src/ dst/Copy recursively, preserving everything
mv old newMove / rename
rm -rf dir/Remove recursively, forced — no undo
find . -name "*.log"Find files by name
find . -mtime +7 -deleteDelete files older than 7 days
du -sh dir/Total size of a directory
df -hTDisk usage by filesystem, with type
ln -s target linkCreate a symbolic link
readlink -f linkResolve a symlink’s real target
basename /path/file.txtfile.txt
dirname /path/file.txt/path

Permissions & Ownership

CommandDescription
chmod 644 filerw-r–r– (standard file)
chmod 755 filerwxr-xr-x (standard executable)
chmod u+x fileAdd execute for owner
chmod -R 755 dir/Apply recursively
chown user:group fileChange owner and group
chgrp group fileChange group only
umaskShow default permission mask
chmod +t dir/Sticky bit (only owner can delete own files)
chmod u+s filesetuid — run as file’s owner

Users & Groups

CommandDescription
idShow UID, GID, groups
whoamiCurrent username
sudo useradd -m -s /bin/bash userCreate user with home dir
sudo passwd userSet/change password
sudo userdel -r userDelete user + home directory
sudo usermod -aG group userAdd to a group (append!)
groups userList a user’s groups
su - userFull login shell as another user
sudo -u user commandRun one command as another user
visudoSafely edit /etc/sudoers

Processes & Jobs

CommandDescription
ps auxAll processes, BSD-style
ps -ef --forestProcess tree
top / htopLive process monitor
kill 1234SIGTERM — graceful stop
kill -9 1234SIGKILL — force stop, uncatchable
pkill -f "pattern"Kill by command-line match
jobsList background jobs
fg %1 / bg %1Foreground / background a job
nohup cmd &Survive terminal logout
nice -n 10 cmdStart with lower priority
renice -n 5 -p 1234Change priority of running process

Disk & Storage

CommandDescription
lsblk -fBlock devices + filesystems
df -iInode usage (can block writes even with free space)
mount /dev/sdb1 /mntMount a device
umount /mntUnmount
mkfs.ext4 /dev/sdb1Format as ext4
lsof +L1Deleted files still held open (space not freed)
free -hRAM and swap usage
swapon --showActive swap devices

Networking

CommandDescription
ip aShow interfaces + IPs
ip route showRouting table
ss -tulnpListening ports + owning process
dig +short example.comDNS lookup, short output
curl -I https://hostHTTP headers only
curl -o /dev/null -s -w "%{http_code}\n" urlJust the status code
nc -zv host portCheck if a TCP port is open
traceroute hostHop-by-hop path
mtr hostContinuous traceroute + loss stats

Text Processing

CommandDescription
grep -i "text" fileCase-insensitive search
grep -r "text" dir/Recursive search
grep -v "text" fileInvert match (exclude)
sed 's/old/new/g' fileReplace all occurrences (stdout)
sed -i 's/old/new/g' fileReplace in place
awk '{print $1}' filePrint first column
awk -F: '{print $1}' fileCustom field separator
sort | uniq -cCount duplicate lines (needs sorted input)
cut -d, -f1 fileExtract field by delimiter
wc -l fileCount lines

Package Management

CommandDescription
sudo apt update && sudo apt upgradeDebian/Ubuntu: refresh index + upgrade
sudo apt install pkgInstall a package
sudo dnf install pkgRHEL/Fedora equivalent
dpkg -L pkgFiles installed by a .deb package
rpm -qa | grep pkgQuery installed RPM packages

Archiving & Compression

CommandDescription
tar -czvf archive.tar.gz dir/Create gzip-compressed archive
tar -xzvf archive.tar.gzExtract
tar -tvf archive.tarList contents without extracting
rsync -avh src/ dst/Sync, preserving attributes
rsync -avh --dry-run --delete src/ dst/Preview a mirror sync before running it

systemd & Logs

CommandDescription
systemctl status serviceCurrent state + recent logs
systemctl restart serviceRestart
systemctl enable --now serviceEnable at boot + start now
systemctl daemon-reloadReload unit files after editing
journalctl -u service -fFollow a service’s logs live
journalctl -b -1Logs from the previous boot
systemd-analyze blameWhich services slow down boot

Signals Quick Reference

SignalNumberMeaning
SIGHUP1Hangup / reload config
SIGINT2Ctrl+C
SIGTERM15Graceful stop (default kill)
SIGKILL9Force stop — cannot be caught

File Permission Numbers

OctalMeaning
644rw-r–r– — standard file
755rwxr-xr-x — standard executable/directory
600rw——- — private file (e.g. SSH keys)
700rwx—— — private directory
777rwxrwxrwx — full access, avoid in production

Production Considerations

  • This cheatsheet trades explanation for speed — if a command’s behavior isn’t obvious from its flags, check the corresponding Linux Commands article before running it against production.
  • Anything marked destructive (rm -rf, --delete) deserves a --dry-run/manual double-check pass in production, cheatsheet or not.

Quick Interview Answer

“A command cheatsheet is meant for fast recall under pressure — permission octals, signal numbers, and the handful of flags you use constantly (-la, -czvf, -tulnp) are worth memorizing outright, while anything unfamiliar is worth pausing on rather than pattern-matching from a sheet, especially for destructive operations.”

Add More Questions to This Guide

Know a question that should be here? Share it and help the community!

Open Google Form