Linux CLI Cheatsheet
Quick reference for daily Linux commands on development machines, servers, and Embedded Linux boards.
Files, Directories & Search
ls -lah # Detailed list with hidden files and human-readable sizes
find . -name "*.bb" # Find files by name
grep -rn "pattern" dir/ # Recursive text search with line numbers
rg "pattern" # Faster search with ripgrep
tar -czvf out.tar.gz dir/ # Create tar.gz archive
tar -xzvf out.tar.gz # Extract tar.gz archive
rsync -avh --progress src/ dst/ # Sync directories safely
Permissions
chmod +x script.sh # Add execute permission
chmod 600 ~/.ssh/id_ed25519 # Owner read/write only (required for SSH keys)
chown -R user:group dir/ # Change ownership recursively
Processes & System
ps aux | grep <name> # Find running processes
top / htop # Monitor CPU and memory in real time
kill -9 <PID> # Force stop a process
df -h # Check disk space usage
du -sh * # Show size of each subfolder
free -h # Check memory and swap usage
uname -a # Show kernel version and CPU architecture
Services & Logs (systemd)
systemctl status <service> # Check service status
sudo systemctl restart <service>
sudo systemctl enable --now <service>
journalctl -u <service> -f # Follow service logs in real time
journalctl -p err -b # Show error logs since last boot
dmesg -T | tail -n 50 # Show recent kernel logs with timestamps
Networking & SSH
ip a # Show IP addresses of interfaces
ip r # Show routing table
ss -tulpn # Show listening TCP/UDP ports
curl -I https://example.com # Check HTTP response headers
ssh user@host # Open SSH session
scp file.txt user@host:/tmp/ # Copy file over SSH
ssh -L 8080:localhost:80 user@host # Local port forwarding
Quick Text Processing
head -n 20 file.log # Show first 20 lines
tail -f file.log # Follow newly appended log lines
awk '{print $1, $3}' file # Extract whitespace-separated columns
sed -i 's/old/new/g' file # Replace text in place
sort file | uniq -c # Count occurrences of each line
References
- GNU Coreutils Manual
- tldr pages — Short examples for common CLI tools.
- ExplainShell — Break down any shell command and its flags.