Linux Commands Cheat Sheet

Quick reference for essential Linux terminal commands. File management, permissions, processes, networking, text processing, and system info — all in one page.

File Management Permissions & Ownership Text Processing Process Management Networking Disk & System Archives & Compression Pipes & Redirection

File Management

ls -la List all files with details
cd /path/to/dir Change directory
pwd Print working directory
mkdir -p dir/sub Create directory (including parents)
cp -r src dest Copy file/directory recursively
mv old new Move or rename file
rm -rf dir Remove directory recursively (careful!)
touch file.txt Create empty file or update timestamp
ln -s target link Create symbolic link
find . -name "*.js" Find files by name pattern

Permissions & Ownership

chmod 755 file Set permissions (rwxr-xr-x)
chmod +x script.sh Make file executable
chown user:group file Change owner and group
chown -R user dir/ Change owner recursively
umask 022 Set default permission mask
sudo command Run as superuser
su - username Switch user

Text Processing

cat file.txt Display file contents
head -20 file / tail -20 file First / last 20 lines
tail -f log.txt Follow file in real-time
grep -rn "pattern" dir/ Search recursively with line numbers
sed "s/old/new/g" file Find and replace in file
awk '{print $1}' file Print first column
sort file | uniq Sort and deduplicate
wc -l file Count lines in file
cut -d"," -f1 file.csv Extract first column (CSV)
diff file1 file2 Compare two files

Process Management

ps aux List all running processes
top / htop Interactive process viewer
kill PID / kill -9 PID Terminate / force-kill process
killall name Kill all processes by name
bg / fg Background / foreground job
nohup cmd & Run in background, survives logout
jobs List background jobs
Ctrl+C / Ctrl+Z Interrupt / suspend process

Networking

curl -X GET url HTTP request
wget url Download file
ssh user@host SSH into remote server
scp file user@host:/path Copy file to remote server
netstat -tlnp / ss -tlnp List listening ports
ping host Test connectivity
dig domain / nslookup domain DNS lookup
ifconfig / ip addr Show network interfaces

Disk & System

df -h Disk space usage (human-readable)
du -sh dir/ Directory size
free -h Memory usage
uname -a System information
uptime System uptime and load
whoami Current username
env / printenv Show environment variables
export VAR=value Set environment variable
crontab -e Edit cron jobs
systemctl status service Check service status (systemd)

Archives & Compression

tar -czf archive.tar.gz dir/ Create gzipped archive
tar -xzf archive.tar.gz Extract gzipped archive
tar -xjf archive.tar.bz2 Extract bzip2 archive
zip -r archive.zip dir/ Create zip archive
unzip archive.zip Extract zip archive
gzip file / gunzip file.gz Compress / decompress with gzip

Pipes & Redirection

cmd1 | cmd2 Pipe output of cmd1 to cmd2
cmd > file Redirect stdout to file (overwrite)
cmd >> file Redirect stdout to file (append)
cmd 2>&1 Redirect stderr to stdout
cmd > /dev/null 2>&1 Suppress all output
cmd < file Read input from file
cmd1 && cmd2 Run cmd2 only if cmd1 succeeds
cmd1 || cmd2 Run cmd2 only if cmd1 fails
Step-by-Step Guide

How to Build Docker Compose

Read Guide →

More Cheat Sheets