This cheatsheet is designed for learners of the Linux Masterclass by Happywala Engineer . It provides quick access to essential Linux commands, organized by category, to help you navigate, manage, and master Linux systems effectively.
Shell and Navigation Basics
Description
Commands
Print working directory
pwd
List directory (detailed, human-readable)
ls -lah
Change directory (go back / home)
cd .., cd ~
Show hidden files
ls -a
Path of a command
which ls
Command help
command --help
Manual page
man command
Files and Directories
Description
Commands
Create file (empty)
touch file.txt
View file (short/long/paged)
cat file.txt, less file.txt, head -n 20 file.txt, tail -n 50 file.txt
Create directory (recursive)
mkdir -p dir/subdir
Copy (file/dir)
cp source.txt dest.txt, cp -r src_dir dest_dir
Move / rename
mv old.txt new.txt, mv file.txt dir/
Remove (file/dir)
rm file.txt, rm -r dir, rm -rf dir (dangerous)
Find by name (case-insensitive)
find . -iname "pattern"
Find recently modified
find . -type f -mtime -1
Locate files (indexed)
locate filename (update index: sudo updatedb)
Text Processing Essentials
Description
Commands
Search in files (recursive, numbered)
grep -Rni "error" /var/log
Filter columns
cut -d',' -f2 file.csv
Sort unique with counts
sort file.txt | uniq -c | sort -nr
Replace text (in-place backup)
sed -i.bak 's/old/new/g' file.txt
Column arithmetic/reporting
awk -F, '{sum+=$2} END{print sum}' file.csv
Word/line/byte counts
wc -w file.txt, wc -l file.txt
Permissions and Ownership
Description
Commands
Show permissions
ls -l
Change mode (rwx)
chmod 644 file, chmod 755 script.sh, chmod +x script.sh
Change owner/group
sudo chown user:group file
Set default perms via umask (typical)
umask 022
Explain numeric perms quickly
r=4, w=2, x=1 โ 7 = rwx, 6 = rw-, 5 = r-x, 4 = r--
Users and Groups
Description
Commands
Current user / effective identity
whoami, id
Add user / set password
sudo adduser alice, sudo passwd alice
Add to group
sudo usermod -aG docker alice
List users logged in
w, who
Switch user / root shell
su - alice, sudo -i
Processes and Jobs
Description
Commands
List processes (wide)
ps aux
Find process by name
pgrep -a nginx
Kill gracefully/force
kill PID, kill -9 PID (last resort)
Foreground/background
command &, jobs, fg %1, bg %1
Nice/renice priority
nice -n 10 command, renice 5 -p PID
System Info and Monitoring
Description
Commands
Live system view
top, htop (install)
Memory usage
free -h
CPU/load averages
uptime
Disk usage (filesystem)
df -h
Directory size summary
du -sh dir/
OS release/kernel
cat /etc/os-release, uname -r
Services status
systemctl status nginx
Networking Basics
Description
Commands
IP addresses / links
ip addr, ip link
Reachability
ping -c 4 8.8.8.8
DNS lookup
dig example.com, nslookup example.com
Routes
ip route
Open ports / listeners
ss -tulpen
HTTP requests
curl -I https://example.com, wget URL
SSH / copy over SSH
ssh user@host, scp file user@host:/path
Packages and Software
Task
Commands
Debian/Ubuntu update & install
sudo apt update && sudo apt upgrade, sudo apt install pkg
RHEL/CentOS/Fedora install
sudo dnf install pkg (or yum on older)
Snap install
sudo snap install app
View package files
dpkg -L pkg, rpm -ql pkg
Archive and Compression
Description
Commands
Create/extract tar
tar -cvf archive.tar dir/, tar -xvf archive.tar
Tar with gzip/bzip2/xz
tar -czvf archive.tar.gz dir/, tar -cjvf archive.tar.bz2 dir/, tar -cJvf archive.tar.xz dir/
Extract auto (any tar.*)
tar -xvf archive.tar.*
Zip/unzip
zip -r archive.zip dir/, unzip archive.zip
gzip/gunzip single file
gzip file, gunzip file.gz
Disk, Storage, and Filesystems
Description
Commands
Block devices
lsblk
Mount / unmount
sudo mount /dev/sdb1 /mnt, sudo umount /mnt
Filesystem check
sudo fsck /dev/sdb1 (offline)
Swap summary
swapon --show
Create image quickly
dd if=/dev/zero of=file.img bs=1M count=100 (be careful)
Services, Logs, and Scheduling
Description
Commands
Manage services
sudo systemctl enable nginx, sudo systemctl start nginx, sudo systemctl restart nginx
Journal logs
journalctl -u nginx --since "1 hour ago" -n 100 -f
Syslog tail
tail -f /var/log/syslog (Debian/Ubuntu), tail -f /var/log/messages (RHEL)
Cron edit/list
crontab -e, crontab -l
Sample cron (every 5 min)
*/5 * * * * /path/script.sh >> /var/log/script.log 2>&1
Shell Productivity and Safety
Description
Commands
Command history / rerun
history, !123
Prevent disasters (interactive rm)
alias rm='rm -i'
Persistent aliases
Add to ~/.bashrc, then source ~/.bashrc
Export environment variable
export APP_ENV=prod
Paths
echo $PATH, export PATH="$PATH:/opt/bin"
Terminal Editors
Editor
Commands / Shortcuts
Nano quick edit
nano file.txt (Ctrl+O save, Ctrl+X exit)
Vim
vim file.txt (i insert, Esc :wq save & quit, :q! force quit)
Sudo Essentials
Description
Commands
Run as root
sudo command
Edit sudoers safely
sudo visudo
Allow a user in sudo group (Debian/Ubuntu)
sudo usermod -aG sudo alice
Save The Day
Description
Commands
Tail logs with highlight
tail -f app.log | grep --line-buffered -E "ERROR|WARN"
Find big files (>100MB)
find / -type f -size +100M 2>/dev/null | sort
List top disk hogs
du -ah /var | sort -hr | head -n 50
Check whoโs using a port
sudo lsof -i :8080
Quick Mental Models
Principle
Explanation
Example
Everything is a file
Devices, sockets, and processes expose file-like interfaces, making interaction consistent.
/dev/sda (disk), /proc/cpuinfo (process info)
Pipes compose tools
Commands can be chained together to build powerful data flows.
cmd1 | cmd2 | cmd3
Small, sharp tools
Use focused commands together rather than one giant command.
grep "error" logfile | sort | uniq -c
Tips, Tricks, Roadmaps, Resources, Networking, Motivation, Guidance, and Cool Stuff โฅ