Linux Cheatsheet
Table of Contents
- Filesystem & Navigation
- Files & Directories
- Permissions
- Users & Groups
- Processes
- System Info
- Networking
- Package Management
- Archives & Compression
- Search & Filter
- SSH & Remote
- Disk & Storage
- Systemd & Services
- Cron Jobs
- Pipes & Redirects
- Useful Shortcuts
Filesystem & Navigation
| Command |
Description |
pwd |
Print current working directory |
ls |
List directory contents |
ls -la |
Detailed list including hidden files |
ls -lh |
Human-readable file sizes |
cd /path |
Change directory |
cd ~ |
Go to home directory |
cd .. |
Go up one directory |
cd - |
Go to previous directory |
tree |
Display directory structure as tree |
tree -L 2 |
Tree structure with depth 2 |
Files & Directories
| Command |
Description |
touch file.txt |
Create empty file |
mkdir folder |
Create directory |
mkdir -p a/b/c |
Create nested directories |
cp source dest |
Copy file |
cp -r folder/ dest/ |
Copy directory recursively |
mv old new |
Move / rename file |
rm file.txt |
Delete file |
rm -rf folder/ |
Delete directory recursively (caution!) |
ln -s target link |
Create symbolic link |
cat file.txt |
Display file contents |
head -n 20 file |
Show first 20 lines |
tail -n 20 file |
Show last 20 lines |
tail -f logfile |
Follow log file in real time |
less file.txt |
View file page by page |
wc -l file.txt |
Count lines |
diff file1 file2 |
Compare files |
Permissions
| Command |
Description |
chmod 755 file |
Set permissions (rwxr-xr-x) |
chmod +x script.sh |
Make executable |
chmod -R 644 folder/ |
Set permissions recursively |
chown user:group file |
Change owner |
chown -R user:group folder/ |
Change owner recursively |
Reading Permissions
-rwxr-xr-x
||| ||| |||
||| ||| └── Others: r-x (5)
||| └───── Group: r-x (5)
└──────── Owner: rwx (7)
| Value |
Meaning |
r (4) |
Read |
w (2) |
Write |
x (1) |
Execute |
Users & Groups
| Command |
Description |
whoami |
Show current user |
id |
Show user ID and groups |
sudo useradd -m user |
Create new user |
sudo passwd user |
Set password |
sudo userdel -r user |
Delete user |
sudo usermod -aG group user |
Add user to group |
groups user |
Show user's groups |
su - user |
Switch user |
sudo -i |
Open root shell |
Processes
| Command |
Description |
ps aux |
Show all running processes |
ps aux | grep name |
Search process by name |
top |
Display processes in real time |
htop |
Interactive process monitor |
kill PID |
Terminate process |
kill -9 PID |
Force kill process |
killall name |
Kill all processes by name |
bg |
Send process to background |
fg |
Bring process to foreground |
nohup command & |
Run in background (survives logout) |
jobs |
Show background jobs |
System Info
| Command |
Description |
uname -a |
Show kernel info |
hostnamectl |
Hostname and OS info |
uptime |
System uptime |
date |
Date and time |
cal |
Show calendar |
lsb_release -a |
Show distribution |
cat /etc/os-release |
Show OS version |
free -h |
Show memory (RAM) usage |
lscpu |
Show CPU info |
lsblk |
Show block devices |
dmesg | tail |
Show kernel messages |
Networking
| Command |
Description |
ip a |
Show IP addresses |
ip r |
Show routing table |
ping host |
Check reachability |
curl url |
Perform HTTP request |
curl -I url |
Show HTTP headers only |
wget url |
Download file |
ss -tulnp |
Show open ports |
netstat -tulnp |
Show open ports (legacy) |
dig domain |
DNS lookup |
nslookup domain |
DNS query |
traceroute host |
Trace route to host |
iptables -L |
Show firewall rules |
ufw status |
UFW firewall status |
ufw allow 22 |
Allow port 22 (SSH) |
Package Management
Debian / Ubuntu (apt)
| Command |
Description |
sudo apt update |
Update package lists |
sudo apt upgrade |
Upgrade packages |
sudo apt install package |
Install package |
sudo apt remove package |
Uninstall package |
sudo apt autoremove |
Remove unused packages |
apt search name |
Search for package |
dpkg -l |
List installed packages |
RHEL / Fedora (dnf/yum)
| Command |
Description |
sudo dnf update |
Update packages |
sudo dnf install package |
Install package |
sudo dnf remove package |
Uninstall package |
dnf search name |
Search for package |
rpm -qa |
List installed packages |
Archives & Compression
| Command |
Description |
tar -czf archive.tar.gz folder/ |
Compress directory (gzip) |
tar -xzf archive.tar.gz |
Extract archive (gzip) |
tar -cjf archive.tar.bz2 folder/ |
Compress (bzip2) |
tar -xjf archive.tar.bz2 |
Extract (bzip2) |
tar -tf archive.tar.gz |
List archive contents |
zip -r archive.zip folder/ |
Create ZIP archive |
unzip archive.zip |
Extract ZIP |
gzip file |
Compress file |
gunzip file.gz |
Decompress file |
Search & Filter
| Command |
Description |
find /path -name "*.txt" |
Find files by name |
find /path -type d -name "logs" |
Find directories |
find /path -size +100M |
Find files larger than 100 MB |
find /path -mtime -7 |
Modified in the last 7 days |
find /path -perm 777 |
Find files with permission 777 |
grep "pattern" file |
Search in file |
grep -r "pattern" folder/ |
Search recursively |
grep -i "pattern" file |
Case-insensitive search |
grep -n "pattern" file |
With line numbers |
grep -c "pattern" file |
Count matches |
locate filename |
Fast file search (index-based) |
which command |
Show path of a command |
whereis command |
Find binaries and man pages |
SSH & Remote
| Command |
Description |
ssh user@host |
SSH connection |
ssh -p 2222 user@host |
SSH on custom port |
ssh-keygen -t ed25519 |
Generate SSH key |
ssh-copy-id user@host |
Copy public key to server |
scp file user@host:/path |
Copy file to server |
scp user@host:/path/file . |
Copy file from server |
rsync -avz source/ dest/ |
Synchronize directories |
rsync -avz -e ssh source/ user@host:/dest/ |
Sync over SSH |
Disk & Storage
| Command |
Description |
df -h |
Show disk usage |
du -sh folder/ |
Show directory size |
du -h --max-depth=1 |
Size per subdirectory |
ncdu |
Interactive disk usage |
lsblk |
List block devices |
fdisk -l |
Show partitions |
mount /dev/sdb1 /mnt |
Mount partition |
umount /mnt |
Unmount partition |
Systemd & Services
| Command |
Description |
systemctl start service |
Start service |
systemctl stop service |
Stop service |
systemctl restart service |
Restart service |
systemctl status service |
Show service status |
systemctl enable service |
Enable service at boot |
systemctl disable service |
Disable service at boot |
systemctl list-units --type=service |
List all services |
journalctl -u service |
Show service logs |
journalctl -f |
Follow logs in real time |
journalctl --since "1 hour ago" |
Logs from the last hour |
Cron Jobs
| Command |
Description |
crontab -e |
Edit cron jobs |
crontab -l |
List cron jobs |
crontab -r |
Remove all cron jobs |
Cron Syntax
┌───────────── Minute (0-59)
│ ┌───────────── Hour (0-23)
│ │ ┌───────────── Day of Month (1-31)
│ │ │ ┌───────────── Month (1-12)
│ │ │ │ ┌───────────── Day of Week (0-6, 0=Sunday)
│ │ │ │ │
* * * * * command
| Example |
Description |
0 * * * * |
Every hour |
0 2 * * * |
Daily at 02:00 |
0 0 * * 0 |
Every Sunday at midnight |
*/5 * * * * |
Every 5 minutes |
0 9-17 * * 1-5 |
Hourly Mon-Fri, 9 AM - 5 PM |
Pipes & Redirects
| Command |
Description |
command > file |
Write output to file (overwrite) |
command >> file |
Append output to file |
command 2> error.log |
Redirect errors to file |
command &> all.log |
Redirect all output to file |
command1 | command2 |
Pipe output as input |
command | tee file |
Display and save output |
command | sort |
Sort output |
command | uniq |
Remove duplicates |
command | wc -l |
Count lines |
command | xargs cmd |
Pass output as arguments |
Useful Shortcuts
| Shortcut |
Description |
Ctrl + C |
Cancel running command |
Ctrl + Z |
Suspend process |
Ctrl + D |
Exit shell / send EOF |
Ctrl + L |
Clear terminal |
Ctrl + R |
Search command history |
Ctrl + A |
Move cursor to line start |
Ctrl + E |
Move cursor to line end |
Ctrl + W |
Delete last word |
!! |
Repeat last command |
!$ |
Repeat last argument |
history |
Show command history |
alias ll='ls -la' |
Create alias |