Linux Cheat Sheet
Complete reference guide for Linux with interactive examples and live playground links
Click on any section to jump directly to it
Basic Commands
File System
Basic file system commands
Linux
# Navigation
cd /path/to/directory
cd .. # parent directory
cd ~ # home directory
pwd # current directory
# List files
ls
ls -l # detailed
ls -a # hidden files
ls -lh # human readable
# File operations
cp file1 file2
mv file1 file2
rm file
rm -r directory
mkdir directory
File Content
File content commands
Linux
# View files
cat file
less file
head -n 10 file
tail -n 10 file
tail -f file # follow
# Search content
grep "pattern" file
grep -r "pattern" directory
find . -name "*.txt"
find . -type f -mtime -7
Permissions
File permission commands
Linux
# View permissions
ls -l file
stat file
# Change permissions
chmod 755 file
chmod u+x file
chmod -R 755 directory
# Change ownership
chown user:group file
chown -R user:group directory
Advanced Commands
Process Management
Process management commands
Linux
# View processes
ps
ps aux
top
htop
# Process control
kill PID
kill -9 PID # force kill
killall process_name
pkill pattern
# Background jobs
command &
nohup command &
jobs
fg %1
bg %1
System Info
System information commands
Linux
# System information
uname -a
hostnamectl
lsb_release -a
# Hardware info
lscpu
free -h
df -h
du -sh directory
# Network info
ifconfig
ip addr
netstat -tulpn
ss -tulpn
Package Management
Package management commands
Linux
# Debian/Ubuntu
apt update
apt upgrade
apt install package
apt remove package
apt search package
# Red Hat/CentOS
yum update
yum install package
yum remove package
yum search package
# Arch Linux
pacman -Syu
pacman -S package
pacman -R package
pacman -Ss package
Networking
Network Commands
Network commands
Linux
# Network configuration
ifconfig
ip addr
ip route
nmcli
# Network testing
ping host
traceroute host
mtr host
nslookup domain
dig domain
# Network monitoring
netstat -tulpn
ss -tulpn
iftop
nethogs
Firewall
Firewall commands
Linux
# iptables
iptables -L
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -D INPUT -p tcp --dport 80 -j ACCEPT
# ufw (Ubuntu)
ufw status
ufw allow 80/tcp
ufw deny 80/tcp
ufw enable
ufw disable
# firewalld (RHEL)
firewall-cmd --list-all
firewall-cmd --add-port=80/tcp
firewall-cmd --remove-port=80/tcp
SSH
SSH commands
Linux
# SSH connection
ssh user@host
ssh -p port user@host
ssh -i key.pem user@host
# SSH config
Host myserver
HostName example.com
User username
Port 22
IdentityFile ~/.ssh/id_rsa
# SSH key management
ssh-keygen -t rsa
ssh-copy-id user@host
System Administration
User Management
User management commands
Linux
# User operations
useradd username
userdel username
usermod -aG group username
passwd username
# Group operations
groupadd groupname
groupdel groupname
groupmod -n newname oldname
# User info
id username
groups username
who
w
Service Management
Service management
Linux
# systemd
systemctl status service
systemctl start service
systemctl stop service
systemctl restart service
systemctl enable service
# Service files
[Unit]
Description=My Service
After=network.target
[Service]
Type=simple
User=myuser
ExecStart=/usr/bin/myprogram
Restart=always
[Install]
WantedBy=multi-user.target
Logs
Log management
Linux
# System logs
journalctl
journalctl -f
journalctl -u service
journalctl --since "1 hour ago"
# Log files
/var/log/syslog
/var/log/auth.log
/var/log/kern.log
/var/log/dmesg
# Log rotation
logrotate -d /etc/logrotate.conf
Best Practices
Security
Security best practices
Linux
# Security measures
- Regular updates
- Firewall configuration
- SSH hardening
- User permissions
- File permissions
# Password policy
- Strong passwords
- Regular rotation
- Password complexity
- Account locking
- Failed login monitoring
# System hardening
- Disable unused services
- Remove unnecessary packages
- Configure SELinux/AppArmor
- Regular security audits
- Backup strategy
Performance
Performance best practices
Linux
# System monitoring
- Resource usage
- Process management
- Disk usage
- Network traffic
- Log analysis
# Optimization
- Kernel parameters
- File system tuning
- Network optimization
- Service optimization
- Cache management
# Maintenance
- Regular updates
- Disk cleanup
- Log rotation
- Backup verification
- System health checks
Troubleshooting
Troubleshooting practices
Linux
# Common issues
- System boot problems
- Network connectivity
- Service failures
- Disk space issues
- Permission problems
# Debugging tools
- System logs
- Process monitoring
- Network tools
- Disk utilities
- Performance analysis
# Recovery
- Backup restoration
- System rescue
- Data recovery
- Service recovery
- Configuration fixes
Linux - Interactive Developer Reference
Hover over code blocks to copy or run in live playground