Linux Cheatsheet
Essential Linux commands for DevOps engineers — file system, processes, networking, permissions, systemd, and performance.
File System
ls -lahList files with human-readable sizes and hidden files
find / -name '*.log' -mtime -7Find all .log files modified in last 7 days
find /var/log -size +100MFind files larger than 100MB
du -sh /var/log/*Show disk usage of each item in /var/log
df -hShow disk space usage on all filesystems
df -ihShow inode usage (useful when disk full but du shows space)
cp -r src/ dst/Copy directory recursively
rsync -avz src/ user@host:dst/Sync directory to remote (preserves permissions)
tar -czf archive.tar.gz /path/to/dirCreate compressed tarball
tar -xzf archive.tar.gz -C /targetExtract tarball to specific directory
ln -s /actual/path /symlink/pathCreate symbolic link
stat filenameShow file metadata (permissions, size, timestamps)
List files with human-readable sizes and hidden files
Find all .log files modified in last 7 days
Find files larger than 100MB
Show disk usage of each item in /var/log
Show disk space usage on all filesystems
Show inode usage (useful when disk full but du shows space)
Copy directory recursively
Sync directory to remote (preserves permissions)
Create compressed tarball
Extract tarball to specific directory
Create symbolic link
Show file metadata (permissions, size, timestamps)
Permissions
chmod 755 script.shrwx for owner, rx for group/others
chmod 600 ~/.ssh/id_rsaRead/write for owner only (SSH key)
chmod -R 644 /var/www/htmlRecursively set permissions
chown user:group fileChange file owner and group
chown -R www-data:www-data /var/wwwRecursively change ownership
umask 022Default permissions mask (new files get 644)
sudo -u www-data commandRun command as another user
visudoSafely edit sudoers file
groups usernameShow groups a user belongs to
usermod -aG docker $USERAdd user to docker group
rwx for owner, rx for group/others
Read/write for owner only (SSH key)
Recursively set permissions
Change file owner and group
Recursively change ownership
Default permissions mask (new files get 644)
Run command as another user
Safely edit sudoers file
Show groups a user belongs to
Add user to docker group
Processes
ps aux | grep nginxFind processes matching nginx
ps aux --sort=-%cpu | head -10Top 10 CPU-consuming processes
top -b -n 1 | head -20Snapshot of top processes (non-interactive)
htopInteractive process viewer (install separately)
kill -9 PIDForce kill process by PID
pkill -f 'python app.py'Kill process by name/pattern
lsof -i :8080Which process is using port 8080
fuser -k 8080/tcpKill process using port 8080
nohup command &Run command immune to hangups
command &Run command in background
jobsList background jobs
fg %1Bring job 1 to foreground
strace -p PIDTrace system calls of a running process
Find processes matching nginx
Top 10 CPU-consuming processes
Snapshot of top processes (non-interactive)
Interactive process viewer (install separately)
Force kill process by PID
Kill process by name/pattern
Which process is using port 8080
Kill process using port 8080
Run command immune to hangups
Run command in background
List background jobs
Bring job 1 to foreground
Trace system calls of a running process
Networking
ss -tlnpShow all listening TCP ports with process names
netstat -tlnpSame as above (older systems)
curl -v https://example.comVerbose HTTP request showing headers
curl -o /dev/null -s -w '%{http_code}' URLGet HTTP status code only
wget -q -O - URLDownload URL content to stdout
nslookup domain.comDNS lookup
dig domain.com ADetailed DNS A record lookup
traceroute domain.comTrace network path to host
nc -zv host 443Test if port is open
iptables -L -n -vList all iptables rules
ip addr showShow all network interfaces and IPs
ip route showShow routing table
tcpdump -i eth0 port 80Capture HTTP traffic on eth0
Show all listening TCP ports with process names
Same as above (older systems)
Verbose HTTP request showing headers
Get HTTP status code only
Download URL content to stdout
DNS lookup
Detailed DNS A record lookup
Trace network path to host
Test if port is open
List all iptables rules
Show all network interfaces and IPs
Show routing table
Capture HTTP traffic on eth0
Systemd & Services
systemctl status nginxShow service status and recent logs
systemctl start|stop|restart nginxStart, stop, or restart service
systemctl enable nginxEnable service to start on boot
systemctl disable nginxDisable service from starting on boot
systemctl reload nginxReload config without downtime
systemctl list-units --failedShow all failed services
journalctl -u nginx -fFollow service logs in real time
journalctl -u nginx --since '1 hour ago'Service logs from last hour
journalctl -p err -bShow error-level logs since last boot
systemctl daemon-reloadReload systemd after changing unit files
Show service status and recent logs
Start, stop, or restart service
Enable service to start on boot
Disable service from starting on boot
Reload config without downtime
Show all failed services
Follow service logs in real time
Service logs from last hour
Show error-level logs since last boot
Reload systemd after changing unit files
Performance & Monitoring
free -hShow RAM and swap usage
vmstat 1 5CPU, memory, I/O stats every 1s (5 times)
iostat -xz 1Disk I/O statistics
sar -u 1 5CPU utilization history
uptimeSystem load average (1, 5, 15 min)
dmesg | tail -20Kernel messages (OOM kills, hardware errors)
cat /proc/cpuinfo | grep processor | wc -lNumber of CPU cores
cat /proc/meminfo | head -5Detailed memory information
lscpuCPU architecture details
lsblkList block devices (disks, partitions)
Show RAM and swap usage
CPU, memory, I/O stats every 1s (5 times)
Disk I/O statistics
CPU utilization history
System load average (1, 5, 15 min)
Kernel messages (OOM kills, hardware errors)
Number of CPU cores
Detailed memory information
CPU architecture details
List block devices (disks, partitions)
Text Processing
grep -r 'error' /var/log/ --include='*.log'Recursive grep in log files
grep -i 'ERROR\|WARN' app.log | tail -50Case-insensitive multi-pattern grep
awk '{print $1, $4}' access.logPrint columns 1 and 4
awk '/ERROR/{count++} END{print count}' app.logCount ERROR occurrences
sed -i 's/old/new/g' file.txtIn-place find and replace
sort -k2 -n file.txtSort by second column numerically
sort | uniq -c | sort -rnCount and sort occurrences
cut -d',' -f1,3 file.csvExtract columns 1 and 3 from CSV
wc -l file.txtCount lines in file
tail -f /var/log/syslog | grep -v DEBUGFollow log, exclude DEBUG lines
jq '.items[] | .metadata.name' data.jsonParse JSON with jq
xargs -I{} command {}Execute command for each stdin line
Recursive grep in log files
Case-insensitive multi-pattern grep
Print columns 1 and 4
Count ERROR occurrences
In-place find and replace
Sort by second column numerically
Count and sort occurrences
Extract columns 1 and 3 from CSV
Count lines in file
Follow log, exclude DEBUG lines
Parse JSON with jq
Execute command for each stdin line