Linux Commands Cheatsheet
Essential Linux commands for web developers. Includes file system, development tools, networking, and system monitoring.
File System Navigation
Basic Navigation
Essential commands for navigating the file system.
# Current directory
pwd
# List files and directories
ls # Basic list
ls -la # Detailed list including hidden
ls -lh # Human readable sizes
ls -R # Recursive list
# Change directory
cd /path # Absolute path
cd ./path # Relative path
cd .. # Parent directory
cd ~ # Home directory
cd - # Previous directory
# Find files
find . -name "*.js" # Find by name
find . -type f -mtime -7 # Files modified in last 7 days
find . -size +10M # Files larger than 10MB
# Search file content
grep "search" file.txt # Search in file
grep -r "search" . # Search recursively
grep -i "CASE" file.txt # Case insensitive
File Operations
Managing files and directories.
# Create
mkdir directory # Create directory
mkdir -p path/to/dir # Create with parents
touch file.txt # Create/update file
# Copy
cp file.txt backup.txt # Copy file
cp -r dir1 dir2 # Copy directory
cp -p file.txt backup # Preserve permissions
# Move/Rename
mv file.txt newname.txt # Rename file
mv file.txt ../ # Move file
mv dir1 dir2 # Move directory
# Delete
rm file.txt # Remove file
rm -r directory # Remove directory
rm -rf directory # Force remove
rmdir empty_dir # Remove empty dir
# Permissions
chmod 755 file.txt # Change permissions
chown user:group file # Change ownership
Development Tools
Package Management
Managing system and development packages.
# APT (Debian/Ubuntu)
apt update # Update package list
apt install package # Install package
apt remove package # Remove package
apt upgrade # Upgrade all packages
# NPM
npm install # Install dependencies
npm install package # Install package
npm update # Update packages
npm run script # Run script
# Git
git clone repo_url # Clone repository
git pull origin main # Pull updates
git status # Check status
git add . # Stage changes
git commit -m "msg" # Commit changes
git push origin main # Push changes
# Docker
docker ps # List containers
docker images # List images
docker-compose up # Start services
docker-compose down # Stop services
Process Management
Managing running processes and services.
# View processes
ps aux # List all processes
top # Interactive process viewer
htop # Enhanced top
# Process control
kill PID # Kill process
killall process # Kill by name
pkill pattern # Kill by pattern
# Background jobs
command & # Run in background
jobs # List background jobs
fg %1 # Bring to foreground
bg %1 # Send to background
# Services
systemctl start service # Start service
systemctl stop service # Stop service
systemctl restart service # Restart service
systemctl status service # Check status
Network Tools
Network Operations
Network monitoring and troubleshooting.
# Network info
ifconfig # Network interfaces
ip addr # IP addresses
netstat -tuln # Open ports
ss -tuln # Socket statistics
# Connectivity
ping domain.com # Test connectivity
curl domain.com # HTTP request
wget url # Download file
dig domain.com # DNS lookup
nslookup domain # Name server lookup
# SSH
ssh user@host # Connect to host
ssh-keygen # Generate SSH key
ssh-copy-id user@host # Copy SSH key
scp file user@host:/path # Secure copy
# Firewall
ufw status # Check firewall
ufw allow 80/tcp # Allow port
ufw deny 80/tcp # Block port
ufw enable/disable # Toggle firewall
Web Server
Apache/Nginx server management.
# Apache
apache2ctl -t # Test config
apache2ctl -S # Show vhosts
systemctl restart apache2 # Restart
# Nginx
nginx -t # Test config
nginx -s reload # Reload config
systemctl restart nginx # Restart
# Logs
tail -f /var/log/nginx/access.log # Live log
tail -f /var/log/apache2/error.log # Error log
journalctl -u nginx # Service logs
grep ERROR /var/log/nginx/*.log # Search logs
System Monitoring
Resource Monitoring
System resource and performance monitoring.
# System resources
free -h # Memory usage
df -h # Disk usage
du -sh directory # Directory size
iostat # IO statistics
vmstat # Virtual memory stats
# CPU info
cat /proc/cpuinfo # CPU details
uptime # Load average
lscpu # CPU architecture
# System monitoring
htop # Interactive monitor
nmon # Performance monitor
iotop # IO monitor
nethogs # Network monitor
# Log monitoring
tail -f /var/log/syslog # System log
dmesg # Kernel log
journalctl -f # System journal
Maintenance
System maintenance and cleanup.
# Disk cleanup
apt clean # Clean package cache
apt autoremove # Remove unused
rm -rf ~/.cache/* # Clear user cache
find /tmp -type f -delete # Clear temp files
# System updates
apt update # Update repos
apt upgrade # Upgrade packages
apt dist-upgrade # Smart upgrade
do-release-upgrade # Version upgrade
# Backup
tar -czf backup.tar.gz dir/ # Create archive
tar -xzf backup.tar.gz # Extract archive
rsync -av source/ dest/ # Sync directories
dd if=/dev/sda of=disk.img # Disk image