Linux Commands Cheatsheet

Common Linux commands cheatsheet, categorized browsing by scenario.

File Operations 14

ls -laList all files (hidden)
cd <dir>Change directory
pwdShow current path
cp -r <src> <dest>Recursively replicate directories
mv <src> <dest>Move/Rename Files
rm -rf <dir>Force recursive deletion of directories
mkdir -p <path>Recursively create directories
touch <file>Create an empty file
ln -s <target> <link>Create softlink
find <dir> -name "<pattern>"Find files by name
locate <pattern>Quickly locate file paths
tree -L 2Tree Display Catalog Structure
du -sh <dir>View Catalog Size
df -hView Disk Usage

Text Processing 12

cat <file>View File Contents
head -n 20 <file>View first 20 rows
tail -f <file>Real-Time Tracking End of File
grep -rn "<pattern>" <dir>Recursive Search Text
sed -i "s/old/new/g" <file>Replace text in place
awk '{print $1}' <file>Extract first column
sort -u <file>Sort and Deduplicate
uniq -c <file>Statistical duplicate rows
wc -l <file>Number of statistical rows
diff <f1> <f2>Compare file differences
cut -d"," -f1 <file>Extract columns by separator
tr "a-z" "A-Z" < <file>Toggle case

Process Management 9

ps auxView all processes
topReal-time process monitoring
htopEnhanced Process Monitoring
kill -9 <pid>Force termination process
killall <name>Terminate process by name
bg / fgBackend/Frontend Switching
nohup <cmd> &The background does not hang up
lsof -i :<port>View Port Occupancy Process
nice -n 10 <cmd>Renice Process

Network Tools 11

ping <host>Test network connectivity
curl -O <url>Download file
wget <url>Download file
ssh user@hostSSH Remote Login
scp <file> user@host:<path>Remote copy of files
netstat -tlnpView Listening Port
ss -tlnpView Listening Ports (New Version)
nslookup <domain>DNS query
dig <domain>DNS Detail Query
ifconfig / ip aView Network Interface
traceroute <host>Traceroute

Permission Management 6

chmod 755 <file>Modify file permissions
chmod +x <file>Add Execution Permission
chown user:group <file>Modify Document Owner
umask 022Set Default Permission Mask
sudo <cmd>Execute as Admin
su - <user>Switch user

Package Management 6

apt install <pkg>Install package (Debian/Ubuntu)
apt update && apt upgradeUpdate all packages
yum install <pkg>Installation Kit (CentOS/RHEL)
dnf install <pkg>Install Package (Fedora)
pacman -S <pkg>Install Package (Arch)
brew install <pkg>Install package (macOS)

Compression/Decompression 8

tar -czf <a>.tar.gz <dir>Compress to tar.gz
tar -xzf <a>.tar.gzUnzip tar.gz
tar -cjf <a>.tar.bz2 <dir>Compressed to tar.bz2
tar -xjf <a>.tar.bz2Unzip tar.bz2
zip -r <a>.zip <dir>Archive Zip
unzip <a>.zipUnzip zip
gzip <file>Compress to gz
gunzip <file>.gzUnzip gz

System Info 8

uname -aView System Information
uptimeView Uptime
free -hView Memory Usage
cat /proc/cpuinfoView CPU Information
lsblkView Block Devices
mount / umountMounting & & Unmounting
systemctl status <service>View service status
journalctl -u <service>View Service Log