Skip to main content

Linux Command Cheatsheet

Linux is the foundation of server development and operations. This cheatsheet organizes essential Linux commands by scenario — from file operations to system administration, each with practical examples. Whether you're new to Linux or need a quick reference, this guide has you covered.

Updated: 2026-07-16·47 commands

Quick Reference

TaskCommand
Print working directorypwd
List filesls -la
Change directorycd /path
View processesps aux / top
Search filesfind / -name "file"
Search contentgrep "text" file
Change permissionschmod 755 file
Check disk usagedf -h / du -sh
Install softwareapt install pkg
Check service statussystemctl status

File Operations

### File & Directory Management

``bash # Current path pwd

# List directory contents ls -la # Detailed (with hidden files) ls -lh # Human-readable sizes ls -ltr # Sort by time, newest last

# Change directory cd /tmp # Go to absolute path cd ~ # Go home cd - # Go to previous directory

# Create & delete mkdir -p a/b/c # Recursively create directories touch file.txt # Create empty file rm -rf dir/ # Recursively force delete (⚠️ dangerous) cp -r src dst # Recursively copy mv src dst # Move or rename `

### View File Content

`bash cat file.txt # Display all less file.txt # Paginated view (Space=next, q=quit) head -n 20 file # First 20 lines tail -f log.log # Follow log in real-time wc -l file # Count lines `

> Tip: rm -rf / will destroy your entire system. Always double-check paths with rm.

Process Management

`bash # View processes ps aux # All processes ps aux | grep nginx # Filter top # Real-time monitor (q to quit, 1 for CPU cores)

# Manage processes kill PID # Terminate by PID kill -9 PID # Force kill (SIGKILL) pkill -f "name" # Terminate by process name nohup command & # Run in background, survive terminal close jobs # List background jobs fg %1 # Bring job to foreground `

Networking

`bash # Diagnostics ping -c 4 8.8.8.8 # Connectivity test curl -I https://example.com # HTTP headers wget -O output.zip https://... # Download file traceroute host # Route tracing

# Ports & connections ss -tulpn # Listening ports (replaces netstat) ss -tulpn | grep :80 # Check port 80

# Remote access ssh user@host -p 22 # SSH login scp file user@host:/path/ # File transfer rsync -av src/ dst/ # Incremental sync `

Search & Find

`bash # Search files find /home -name "*.log" # By filename find /home -type f -size +10M # By type and size

# Search content grep "error" logfile # Basic search grep -r "TODO" src/ # Recursive directory search grep -i "warning" log # Case-insensitive grep -C 3 "error" log # Show 3 lines context

# Locate commands which nginx # Command path whereis nginx # Binary + source + man path `

Permissions

`bash # Change permissions chmod 755 script.sh # rwx r-x r-x chmod +x script.sh # Add executable chmod -R 644 dir/ # Recursive file permissions

# Change owner chown user:group file chown -R user:group dir/

# View permissions ls -la # First column: -rwxr-xr-x `

> Permission bits: r=4, w=2, x=1rwx=7, r-x=5, r--=4, ---=0

Disk Management

`bash # Check disk df -h # Disk space (human-readable) du -sh * # Directory sizes in current dir du -sh /var/log/ # Specific directory total

# Mount management mount # View mounts mount /dev/sdb1 /mnt # Mount device umount /mnt # Unmount `

Package Management

`bash # Debian/Ubuntu (apt) apt update # Update package index apt install nginx # Install package apt remove nginx # Remove package apt search "keyword" # Search packages

# RHEL/CentOS (yum/dnf) yum install nginx # Install dnf install nginx # Fedora (newer) `

> Tip: apt and yum have different commands but similar concepts. Not sure your distro? Run cat /etc/os-release.

System Administration

`bash # System info uname -a # Kernel version hostnamectl # Hostname + OS info uptime # Uptime + load average whoami # Current user

# Service management (systemd) systemctl status nginx # Check service status systemctl start nginx # Start service systemctl stop nginx # Stop service systemctl restart nginx # Restart service systemctl enable nginx # Enable on boot

# Logs journalctl -u nginx # View service logs journalctl -u nginx -n 50 # Last 50 lines journalctl -u nginx -f # Follow in real-time

# System load free -h # Memory usage uptime # Load averages (1m/5m/15m) htop # Interactive monitor (if installed) `

Pro Tips

`bash # Pipe & redirection command | grep "xxx" # Pipe to filter command > file.log # Redirect output (overwrite) command >> file.log # Redirect output (append) command 2>&1 # Redirect stderr too

# Command history history # View history !! # Repeat last command !$ # Last argument of last command ctrl+r # Search history (press repeatedly to cycle)

# Shortcuts ctrl+c # Force quit ctrl+d # Exit shell or EOF ctrl+z # Suspend current task `

Troubleshooting

SymptomCauseFix
command not foundNot installed or not in PATHwhich command to check, use full path /usr/bin/command
Permission deniedNo execute permissionchmod +x file or prefix with sudo
Disk full/ partition at 100%df -h to locate, du -sh /* to find big dirs
Port in useAnother process is listeningss -tulpn \grep :port to find PID, kill PID
Process won't dieZombie processTry kill, then kill -9`, then reboot if needed

File(13)

CommandLevel
pwd
Print working directory
Basic
ls
List directory contents
Basic
cd
Change working directory
Basic
mkdir
Create directories
Basic
touch
Create empty file or update file timestamps
Basic
cp
Copy files or directories
Basic
mv
Move or rename files
Basic
rm
Remove files or directories
rm -rf / will delete your entire system! Always double-check paths
Basic
cat
Display file contents
Basic
less
View file contents page by page
Basic
head
Display first lines of a file
Basic
tail
Display last lines of a file
Basic
wc
Count lines, words, and bytes in a file
Basic

Process(6)

CommandLevel
ps
Display running processes
Basic
top
Real-time view of system processes and resource usage
Intermediate
kill
Terminate a process by PID
Use kill -9 (SIGKILL) as a last resort, prefer kill (SIGTERM) first
Intermediate
nohup
Run command immune to hangups (survives terminal close)
Intermediate
pkill
Kill processes by name
Intermediate
htop
Interactive process viewer (enhanced top)
Intermediate

Network(8)

CommandLevel
ping
Test network connectivity
Basic
curl
Send HTTP requests or download files
Intermediate
wget
Download files from the web
Basic
ss
Socket statistics (modern netstat replacement)
Intermediate
ssh
Remote login to SSH server
Intermediate
scp
Securely copy files over SSH
Intermediate
rsync
Fast incremental file transfer tool
Intermediate
traceroute
Trace the route packets take to a host
Intermediate

Permission(2)

CommandLevel
chmod
Change file or directory permissions
Intermediate
chown
Change file or directory owner
Intermediate

Disk(4)

CommandLevel
df
Report file system disk space usage
Basic
du
Estimate file/directory disk usage
Basic
mount
Mount a filesystem or device
Intermediate
umount
Unmount a mounted filesystem
Intermediate

Package(3)

CommandLevel
apt
Debian/Ubuntu package manager
Intermediate
yum
RHEL/CentOS package manager
Intermediate
dnf
Fedora/RHEL next-gen package manager
Intermediate

System(6)

CommandLevel
uname
Display system kernel information
Basic
uptime
Show system uptime and load averages
Basic
systemctl
systemd service manager
Intermediate
journalctl
View systemd logs
Intermediate
free
Display system memory usage
Basic
hostnamectl
View or set hostname and system info
Basic

Shell(1)

CommandLevel
history
View command history
Basic

FAQ

This cheatsheet is compiled from official tool documentation. Last updated: 2026-07-16.