← All Tools

🖫 Linux Commands Cheat Sheet

Essential terminal reference — 102+ commands

Showing all commands

Files & Directories

ls -la
List all files with details
ls -lh
List files with human-readable sizes
cd /path/to/dir
Change directory
cd -
Go to previous directory
pwd
Print current directory
mkdir -p dir1/dir2/dir3
Create nested directories
cp -r source/ dest/
Copy directory recursively
mv old_name new_name
Move or rename file
rm -rf directory/
Remove directory recursively (careful!)
touch file.txt
Create empty file or update timestamp
ln -s target link_name
Create symbolic link
find / -name "*.log" -mtime +7
Find files modified more than 7 days ago
find . -type f -size +100M
Find files larger than 100MB
find . -name "*.tmp" -delete
Find and delete matching files
tree -L 2
Display directory tree (2 levels deep)
du -sh *
Disk usage of each item
df -h
Show disk space usage

File Viewing & Editing

cat file.txt
Display file contents
less file.txt
View file with pagination
head -20 file.txt
Show first 20 lines
tail -f /var/log/syslog
Follow log file in real-time
wc -l file.txt
Count lines in file
diff file1 file2
Compare two files
sort file.txt | uniq -c | sort -rn
Count and sort unique lines
awk '{print $1, $3}' file.txt
Print specific columns
sed -i 's/old/new/g' file.txt
Find and replace in file
cut -d',' -f1,3 data.csv
Extract columns from CSV

Search & Filter

grep -r "pattern" /path/
Search recursively in files
grep -i "pattern" file.txt
Case-insensitive search
grep -n "pattern" file.txt
Show line numbers with matches
grep -v "pattern" file.txt
Show lines NOT matching pattern
grep -c "pattern" file.txt
Count matching lines
grep -E "pat1|pat2" file.txt
Extended regex (OR pattern)
which command
Find location of command
locate filename
Fast file search (requires updatedb)

Permissions & Ownership

chmod 755 script.sh
rwxr-xr-x (owner: rwx, group+others: rx)
chmod +x script.sh
Add execute permission
chmod -R 644 /path/
Set permissions recursively
chown user:group file
Change file ownership
chown -R user:group /dir/
Change ownership recursively

Process Management

ps aux
List all running processes
ps aux | grep nginx
Find specific process
top
Interactive process viewer
htop
Better interactive process viewer
jobs
List background jobs
bg %1 / fg %1
Send job to background/foreground
lsof -i :8080
Find process using port 8080
nohup command &
Run in background (survives logout)

Networking

curl -s https://api.example.com
HTTP GET request
wget -O output.zip https://example.com/file.zip
Download file
ping -c 4 google.com
Test connectivity
traceroute google.com
Trace network path
nslookup domain.com
DNS lookup
dig domain.com
Detailed DNS lookup
ss -tulnp
Show listening ports
ip addr show
Show IP addresses
ssh user@host
Connect to remote server
scp file.txt user@host:/path/
Copy file to remote
rsync -avz src/ user@host:/dest/
Sync files (incremental)

Archives & Compression

tar -czf archive.tar.gz dir/
Create gzipped archive
tar -xzf archive.tar.gz
Extract gzipped archive
tar -tf archive.tar.gz
List archive contents
zip -r archive.zip dir/
Create zip archive
unzip archive.zip
Extract zip archive
gzip file.txt
Compress file
gunzip file.txt.gz
Decompress gzip file

System Info

uname -a
System information
hostname
Show hostname
uptime
System uptime
free -h
Memory usage
lsblk
List block devices
whoami
Current username
date
Current date and time
env
Show environment variables

Services & Systemd

systemctl start nginx
Start a service
systemctl stop nginx
Stop a service
systemctl restart nginx
Restart a service
systemctl status nginx
Check service status
systemctl enable nginx
Enable service on boot
journalctl -u nginx -f
Follow service logs
journalctl --since "1 hour ago"
View recent system logs

Package Management

apt update && apt upgrade
Update packages (Debian/Ubuntu)
apt install package
Install package (Debian/Ubuntu)
apt remove package
Remove package
apt search keyword
Search packages
yum install package
Install package (RHEL/CentOS)
snap install app
Install snap package

Bash Tricks

!!
Repeat last command
Ctrl+R
Reverse search command history
history | tail -20
Show recent command history
command1 | command2
Pipe output to another command
command > file.txt
Redirect output (overwrite)
command >> file.txt
Redirect output (append)
cmd1 && cmd2
Run cmd2 only if cmd1 succeeds
cmd1 || cmd2
Run cmd2 only if cmd1 fails
alias ll='ls -la'
Create command alias

Cron Jobs

crontab -e
Edit cron jobs
crontab -l
List cron jobs
*/5 * * * * /path/script.sh
Run every 5 minutes
0 2 * * * /path/backup.sh
Run daily at 2 AM
0 0 * * 0 /path/weekly.sh
Run every Sunday at midnight
@reboot /path/startup.sh
Run on system startup
\xF0\x9F\x92\x99 Tip\xF0\x9F\x93\x9A Get Bundle \x244.99