Archive & Compression
tar — Tape Archive
| Command | Description |
|---|---|
tar -czvf file.tar.gz folder/ |
Create a compressed .tar.gz archive |
tar -xzvf file.tar.gz |
Extract a .tar.gz archive |
tar -cjvf file.tar.bz2 folder/ |
Create a .bz2 compressed archive |
tar -xjvf file.tar.bz2 |
Extract a .bz2 archive |
tar -tvf file.tar.gz |
List contents without extracting |
tar -xzvf file.tar.gz -C /path/to/dir/ |
Extract to a specific directory |
tar -czvf file.tar.gz --exclude='*.log' folder/ |
Create archive excluding files |
Flag reference:
| Flag | Meaning |
|---|---|
-c |
Create archive |
-x |
Extract archive |
-z |
Compress/decompress with gzip |
-j |
Compress/decompress with bzip2 |
-v |
Verbose (show progress) |
-f |
Specify filename |
-t |
List archive contents |
-C |
Change to directory before extracting |
zip / unzip
| Command | Description |
|---|---|
zip -r file.zip folder/ |
Recursively zip a folder |
zip file.zip a.txt b.txt |
Zip specific files |
zip -e file.zip folder/ |
Create password-protected zip |
zip -9 -r file.zip folder/ |
Max compression level (1–9) |
unzip file.zip |
Extract zip to current directory |
unzip file.zip -d /path/to/dir/ |
Extract to a specific directory |
unzip -l file.zip |
List contents without extracting |
unzip -o file.zip |
Overwrite files without prompting |
unzip -n file.zip |
Never overwrite existing files |
Date & Time
| Command | Description |
|---|---|
date |
Show current date and time |
date +"%Y-%m-%d" |
Format: 2025-05-29 |
date +"%H:%M:%S" |
Format: 14:30:00 |
date +"%d/%m/%Y %T" |
Format: 29/05/2025 14:30:00 |
date -d "2 days ago" |
Date 2 days in the past |
date -d "next Monday" |
Date of next Monday |
date -s "2025-05-29 14:00:00" |
Set system date/time (root) |
timedatectl |
Show full time/timezone info |
timedatectl set-timezone Asia/Kolkata |
Set timezone |
timedatectl list-timezones |
List all available timezones |
hwclock |
Show hardware clock time |
hwclock --systohc |
Sync hardware clock from system |
cal |
Show current month calendar |
cal 2025 |
Show full year calendar |
uptime |
System uptime and load average |
Common date format specifiers:
| Specifier | Output |
|---|---|
%Y |
4-digit year (2025) |
%m |
Month (01–12) |
%d |
Day (01–31) |
%H |
Hour 24h (00–23) |
%M |
Minutes (00–59) |
%S |
Seconds (00–59) |
%A |
Full weekday (Friday) |
%B |
Full month name (May) |
%s |
Unix timestamp (epoch seconds) |
Networking
Connectivity & DNS
| Command | Description |
|---|---|
ping google.com |
Test connectivity (ICMP) |
ping -c 4 google.com |
Send exactly 4 packets |
traceroute google.com |
Trace packet route to host |
mtr google.com |
Live traceroute (interactive) |
nslookup google.com |
DNS lookup |
dig google.com |
Detailed DNS query |
dig google.com +short |
Short IP-only DNS result |
host google.com |
Simple DNS lookup |
curl ifconfig.me |
Show your public IP |
hostname -I |
Show all local IP addresses |
hostname |
Show machine hostname |
Network Interfaces
| Command | Description |
|---|---|
ip a |
Show all interfaces and IPs |
ip link show |
Show link state of interfaces |
ip route show |
Show routing table |
ip route add default via 192.168.1.1 |
Add default gateway |
ifconfig |
Show interfaces (older systems) |
ifconfig eth0 up |
Bring interface up |
ifconfig eth0 down |
Bring interface down |
Ports & Sockets
| Command | Description |
|---|---|
ss -tuln |
Show listening TCP/UDP ports |
ss -tulnp |
Include process name/PID |
netstat -tuln |
Show listening ports (older) |
netstat -anp |
All connections with PID |
lsof -i :80 |
Which process is using port 80 |
lsof -i TCP |
All TCP connections |
nmap localhost |
Scan open ports on localhost |
nmap -sV 192.168.1.1 |
Scan with service version |
HTTP
| Command | Description |
|---|---|
curl -O https://example.com/file.zip |
Download file (keep name) |
curl -o out.zip https://example.com/file.zip |
Download with custom name |
curl -I https://example.com |
Fetch HTTP headers only |
curl -X POST -d "key=val" https://api.example.com |
HTTP POST request |
wget https://example.com/file.zip |
Download file with wget |
wget -r https://example.com/ |
Recursive site download |
SSH
| Command | Description |
|---|---|
ssh user@host |
Connect to remote host |
ssh -p 2222 user@host |
Connect on custom port |
ssh-keygen -t rsa -b 4096 |
Generate SSH key pair |
ssh-copy-id user@host |
Copy public key to remote host |
ssh -L 8080:localhost:80 user@host |
Local port forwarding |
ssh -R 9090:localhost:3000 user@host |
Remote port forwarding |
Firewall (UFW / iptables)
| Command | Description |
|---|---|
ufw status |
Show firewall status |
ufw enable |
Enable UFW firewall |
ufw allow 22 |
Allow SSH port |
ufw allow 80/tcp |
Allow HTTP |
ufw deny 3306 |
Block MySQL port |
ufw delete allow 80 |
Remove a rule |
iptables -L |
List all iptables rules |
iptables -F |
Flush (clear) all rules |
Process Management
Viewing Processes
| Command | Description |
|---|---|
ps aux |
List all running processes |
| `ps aux | grep nginx` |
ps -ef |
Full-format process list |
top |
Live process monitor |
htop |
Enhanced interactive process viewer |
pgrep nginx |
Get PID of process by name |
pstree |
Show process tree |
pidof nginx |
Find PID of a named process |
Killing
| Command | Description |
|---|---|
kill 1234 |
Send SIGTERM to PID 1234 (graceful) |
kill -9 1234 |
Send SIGKILL (force kill) |
kill -l |
List all signal names |
killall nginx |
Kill all processes named nginx |
pkill -f "python script.py" |
Kill by full command match |
pkill -u username |
Kill all processes of a user |
xkill |
Click a window to kill it (GUI) |
Background & Foreground Jobs
| Command | Description |
|---|---|
command & |
Run command in background |
jobs |
List background jobs |
fg |
Bring last job to foreground |
fg %2 |
Bring job #2 to foreground |
bg |
Resume last job in background |
Ctrl + Z |
Suspend foreground process |
Ctrl + C |
Terminate foreground process |
nohup command & |
Run and persist after logout |
disown %1 |
Detach job from shell |
System Resource Usage
| Command | Description |
|---|---|
free -h |
Memory usage (human-readable) |
vmstat 1 5 |
Virtual memory stats (5 samples) |
iostat |
CPU and I/O statistics |
mpstat |
Per-CPU usage stats |
sar -u 1 3 |
CPU usage over time |
lscpu |
CPU architecture details |
ulimit -a |
Show current resource limits |
ulimit -n 65535 |
Set max open file descriptors |
systemd Service Management
| Command | Description |
|---|---|
systemctl status nginx |
Check service status |
systemctl start nginx |
Start a service |
systemctl stop nginx |
Stop a service |
systemctl restart nginx |
Restart a service |
systemctl reload nginx |
Reload config without restart |
systemctl enable nginx |
Enable at boot |
systemctl disable nginx |
Disable at boot |
systemctl list-units --type=service |
List all services |
journalctl -u nginx |
View service logs |
journalctl -u nginx -f |
Follow live service logs |
journalctl -n 100 --since "1 hour ago" |
Recent logs |
