Home ›
Blog › Linux Commands Cheat Sheet
Linux Commands Cheat Sheet — 100+ Essential Commands
Published: June 2025 • 20 min read • Category: Linux
Whether you're a beginner setting up your first Linux server or an experienced sysadmin managing dozens of machines, having a reliable command reference is essential. This cheat sheet covers 100+ essential Linux commands organized into clear categories — from basic file operations to advanced networking and process management.
1. File & Directory Commands
These are the commands you'll use most frequently — navigating, creating, moving, and inspecting files and directories.
| Command | Description |
pwd | Print working directory — shows your current location |
ls | List directory contents |
ls -la | List all files (including hidden) with details |
ls -lh | List files with human-readable sizes |
cd /path | Change directory to /path |
cd .. | Go up one directory |
cd ~ | Go to home directory |
cd - | Go to previous directory |
mkdir dirname | Create a new directory |
mkdir -p a/b/c | Create nested directories |
touch file.txt | Create an empty file or update timestamp |
cp src dst | Copy file or directory |
cp -r src/ dst/ | Copy directory recursively |
mv old new | Move or rename file/directory |
rm file.txt | Delete a file |
rm -rf dir/ | Delete directory and all contents recursively |
ln -s target link | Create a symbolic link |
find . -name "*.py" | Find files matching a pattern |
locate filename | Quickly find files (uses database) |
cat file.txt | Display entire file contents |
head -20 file.txt | Show first 20 lines |
tail -f log.txt | Follow a file in real time (great for logs) |
wc -l file.txt | Count lines in a file |
du -sh dir/ | Show directory size (human-readable) |
df -h | Show disk space usage |
tree -L 2 | Display directory tree (2 levels) |
stat file.txt | Show detailed file metadata |
file file.txt | Detect file type |
⚠️ Warning: rm -rf is irreversible. Always double-check the path before running it. A misplaced space like rm -rf / tmp/ will delete your entire filesystem.
2. Text Processing & Search
Linux excels at text processing. These commands let you search, filter, transform, and analyze text files efficiently.
| Command | Description |
grep "pattern" file | Search for a pattern in a file |
grep -r "error" /var/log | Recursively search directories |
grep -i "warning" | Case-insensitive search |
grep -n "TODO" *.py | Search with line numbers |
sed 's/old/new/g' file | Find and replace text |
sed -i 's/foo/bar/g' file | Find and replace in-place |
awk '{print $1}' file | Print first column |
awk -F, '{print $2}' csv | Print second field (comma-separated) |
sort file.txt | Sort lines alphabetically |
sort -n file.txt | Sort numerically |
sort -k2 -n file.txt | Sort by second column |
uniq | Remove duplicate consecutive lines |
sort file | uniq -c | Count unique occurrences |
cut -d: -f1 /etc/passwd | Extract first field (colon-delimited) |
tr 'a-z' 'A-Z' | Convert lowercase to uppercase |
diff file1 file2 | Compare two files |
tee output.txt | Read from stdin, write to stdout and file |
xargs command | Build arguments from stdin |
Pipeline Examples
# Find the 10 largest files
du -ah / | sort -rh | head -10
# Count HTTP status codes from access log
awk '{print $9}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head
# Find all Python files modified in the last 7 days
find . -name "*.py" -mtime -7
# Search and replace across all HTML files
find . -name "*.html" -exec sed -i 's/http:/https:/g' {} \;
3. File Permissions & Ownership
Linux uses a permission system based on read (r), write (w), and execute (x) for three categories: owner, group, and others.
| Command | Description |
chmod 755 file | Set rwxr-xr-x permissions |
chmod +x script.sh | Make a script executable |
chmod 600 secret.key | Owner read/write only (secure files) |
chown user:group file | Change file owner and group |
chown -R user:group dir/ | Recursively change ownership |
chgrp group file | Change group ownership |
umask 022 | Set default permission mask |
getfacl file | View ACL permissions |
setfacl -m u:alice:rw file | Set ACL for specific user |
Permission Numbers Quick Reference
| Number | Binary | Permission |
| 7 | 111 | rwx (read, write, execute) |
| 6 | 110 | rw- (read, write) |
| 5 | 101 | r-x (read, execute) |
| 4 | 100 | r-- (read only) |
| 0 | 000 | --- (no permissions) |
4. Process Management
Monitor and control running processes on your Linux system.
| Command | Description |
ps aux | List all running processes |
ps aux | grep nginx | Find specific process |
top | Interactive process monitor |
htop | Better interactive process monitor |
kill PID | Terminate a process (SIGTERM) |
kill -9 PID | Force kill a process (SIGKILL) |
pkill -f "process" | Kill processes by name |
killall nginx | Kill all processes by name |
bg / fg | Resume process in background / foreground |
nohup cmd & | Run command immune to hangups |
jobs | List background jobs |
lsof -i :8080 | Find process using port 8080 |
pgrep -a python | Find process IDs by name |
💡 Tip: Use Ctrl+Z to suspend a running process, then bg to send it to background, or fg to bring it back to foreground.
5. Disk & Storage
| Command | Description |
df -h | Disk space (human-readable) |
df -i | Inode usage |
du -sh * | Size of each item in current directory |
du -sh /var/log | Size of a specific directory |
lsblk | List block devices |
fdisk -l | List disk partitions |
mount /dev/sdb1 /mnt | Mount a filesystem |
umount /mnt | Unmount a filesystem |
ncdu / | Interactive disk usage analyzer |
6. Networking Commands
Essential commands for debugging network issues, checking connectivity, and managing network interfaces. See also our curl cheat sheet for HTTP-specific commands.
| Command | Description |
ping google.com | Test network connectivity |
ping -c 4 google.com | Send exactly 4 packets |
curl ifconfig.me | Get your public IP address |
ip addr show | Show all network interfaces |
ip route | Show routing table |
netstat -tlnp | Show listening TCP ports |
ss -tlnp | Modern alternative to netstat |
nslookup example.com | DNS lookup |
dig example.com | Detailed DNS query |
traceroute example.com | Trace packet route to host |
wget https://example.com/file | Download a file |
scp file.txt user@host:/path | Copy file over SSH |
rsync -avz src/ dst/ | Efficiently sync directories |
nmap -sP 192.168.1.0/24 | Scan local network for hosts |
curl -I https://example.com | Get HTTP headers |
7. System Information
| Command | Description |
uname -a | System information (kernel, hostname, etc.) |
cat /etc/os-release | OS distribution details |
hostname | Show hostname |
uptime | System uptime and load averages |
free -h | Memory usage (human-readable) |
nproc | Number of CPU cores |
lscpu | Detailed CPU information |
lspci | List PCI devices |
lsusb | List USB devices |
date | Show current date and time |
timedatectl | Manage system time and timezone |
dmesg | tail -20 | Recent kernel messages |
systemctl status nginx | Check service status |
journalctl -u nginx -f | Follow service logs |
Need to convert timestamps between formats? Use our Timestamp Converter.
8. User Management
| Command | Description |
whoami | Current username |
id | Current user ID and groups |
useradd -m alice | Create a new user with home directory |
passwd alice | Set password for a user |
userdel -r alice | Delete user and home directory |
usermod -aG docker alice | Add user to a group |
groups alice | Show groups for a user |
su - alice | Switch to another user |
sudo command | Run command as superuser |
9. SSH & Remote Access
Secure Shell is the most common way to access remote Linux servers. See our Docker guide for container-related SSH tips.
| Command | Description |
ssh user@host | Connect to remote server |
ssh -p 2222 user@host | Connect on custom port |
ssh-copy-id user@host | Copy SSH key to remote server |
ssh-keygen -t ed25519 | Generate SSH key pair |
ssh -L 8080:localhost:80 host | Local port forwarding (tunnel) |
ssh -R 3000:localhost:80 host | Remote port forwarding |
scp file user@host:/path | Secure copy file to remote |
scp -r dir/ user@host:/path | Secure copy directory recursively |
sftp user@host | Interactive SFTP session |
10. Package Management
Debian/Ubuntu (apt)
sudo apt update # Update package lists
sudo apt install package # Install a package
sudo apt remove package # Remove a package
sudo apt upgrade # Upgrade all packages
apt search "keyword" # Search for packages
apt show package # Show package details
CentOS/RHEL/Fedora (dnf)
sudo dnf install package # Install a package
sudo dnf remove package # Remove a package
sudo dnf update # Update all packages
dnf search "keyword" # Search for packages
Arch Linux (pacman)
sudo pacman -S package # Install a package
sudo pacman -R package # Remove a package
sudo pacman -Syu # Update all packages
pacman -Ss "keyword" # Search for packages
11. Archiving & Compression
| Command | Description |
tar -czf archive.tar.gz dir/ | Create compressed tarball |
tar -xzf archive.tar.gz | Extract compressed tarball |
tar -cjf archive.tar.bz2 dir/ | Create bz2 compressed tarball |
zip archive.zip file1 file2 | Create a zip archive |
unzip archive.zip | Extract zip archive |
gzip file.txt | Compress a file |
gunzip file.txt.gz | Decompress a gz file |
tar -tzf archive.tar.gz | List contents of tarball |
12. Pro Tips & Tricks
Bash Shortcuts
| Shortcut | Action |
Ctrl + C | Interrupt running command |
Ctrl + Z | Suspend current process |
Ctrl + D | Exit shell / send EOF |
Ctrl + L | Clear terminal screen |
Ctrl + R | Reverse search command history |
Ctrl + A | Move cursor to start of line |
Ctrl + E | Move cursor to end of line |
Ctrl + W | Delete word before cursor |
Alt + . | Insert last argument of previous command |
!! | Repeat last command |
Useful One-Liners
# Generate a secure random password
openssl rand -base64 32
# Or use our online tool: https://hedpy.cn/tools/password-generator
# Create a quick backup
cp important.conf important.conf.bak.$(date +%F)
# Find and delete empty files
find . -type f -empty -delete
# Monitor network connections in real time
watch -n 1 'ss -tlnp'
# Download all images from a page
curl -s https://example.com | grep -o 'src="[^"]*"' | grep -o 'http[^"]*' | xargs -n1 curl -O
# Batch rename files (add .bak extension)
for f in *.conf; do mv "$f" "$f.bak"; done
💡 Pro Tip: Set up shell aliases for commands you use frequently. Add them to ~/.bashrc or ~/.zshrc:
alias ll='ls -lah'
alias gs='git status'
alias gp='git push'
alias dc='docker compose'
alias ..='cd ..'
alias ...='cd ../..'
Conclusion
Mastering these Linux commands will dramatically improve your productivity as a developer, sysadmin, or DevOps engineer. Start with the basics — file navigation, grep, and permissions — then gradually learn the more advanced commands. Bookmark this page as your go-to reference, and check out our Docker commands guide and Git commands guide for more specialized cheat sheets.