Linux Commands Snippet
88 essential Linux sysadmin commands that are long, complex, and hard to remember. Copy, paste, and execute!
Find files by multiple criteria
filesFind files older than 30 days, larger than 100MB, and show details
find /path -type f -name '*.log' -mtime +30 -size +100M -exec ls -lh {} \;
Find and delete old files
filesDelete files older than 30 days
find /var/log -type f -name '*.log' -mtime +30 -delete
Find largest files in directory
filesFind top 20 largest files/directories sorted by size
du -h /path | sort -rh | head -20
Find empty directories
filesFind all empty directories
find /path -type d -empty
Secure copy with compression
networkSCP with compression, recursive, custom port
scp -C -r -P 2222 user@host:/remote/path /local/path
SSH with port forwarding
networkLocal port forwarding: access remote port 80 via local port 8080
ssh -L 8080:localhost:80 -N -f user@remote-host
SSH reverse tunnel
networkReverse tunnel: expose local port 3000 on remote port 9090
ssh -R 9090:localhost:3000 -N -f user@remote-host
TCP SYN port scan
networkStealth SYN scan all ports showing only open ones
nmap -sS -p 1-65535 --open 192.168.1.1
Netcat port scan
networkQuick port scan using netcat on ports 1-1000
nc -zv -w2 192.168.1.1 1-1000
TCP dump specific port
networkCapture 1000 packets on port 80 and save to file
tcpdump -i eth0 port 80 -w capture.pcap -c 1000
Monitor network connections
networkShow most frequent established connections by IP
ss -tunapl | grep ESTABLISHED | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -rn
Detect DDoS attack sources
networkCount connections by IP to identify potential DDoS attackers (shows top 20 IPs with most connections)
netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -rn | head -20
Check process listening on port
processFind which process is using port 8080
lsof -i :8080 | grep LISTEN
Kill all processes by name
processKill all processes matching the pattern
pkill -f "process-name"
Show processes sorted by CPU
processShow top 20 processes by CPU usage
ps aux --sort=-%cpu | head -20
Show processes sorted by memory
processShow top 20 processes by memory usage
ps aux --sort=-%mem | head -20
Run process with low priority
processRun with lowest CPU and I/O priority
nice -n 19 ionice -c 3 command
Change running process priority
processChange CPU priority of existing process
renice -n 10 -p $(pgrep process-name)
Monitor process in background
processRun command persistently after logout
nohup command > output.log 2>&1 & disown
Create tar with progress
filesCreate compressed tar with progress bar
tar -czf - /source | pv -s $(du -sb /source | awk '{print $1}') > backup.tar.gz
Extract tar to specific directory
filesExtract tar skipping top-level directory
tar -xzf archive.tar.gz -C /destination --strip-components=1
Rsync with progress and delete
filesSync directories, show progress, delete extraneous files
rsync -avh --progress --delete /source/ /destination/
Rsync over SSH with compression
filesRsync via SSH with compression and custom port
rsync -avz --progress -e "ssh -p 2222" /local/ user@host:/remote/
Sed replace with backup
textReplace text with automatic backup creation
sed -i.bak 's/old-text/new-text/g' file.txt
Sed delete lines matching pattern
textDelete lines containing specific pattern
sed -i '/pattern-to-delete/d' file.txt
Awk sum column values
textSum first column and print formatted result
awk '{sum+=$1} END {printf "Total: %.2f\n", sum}' file.txt
Awk filter and print multiple columns
textFilter CSV where column 3 > 100, format output
awk -F, '$3 > 100 {printf "%-20s %10.2f\n", $1, $3}' data.csv
Grep with context lines
textSearch with 3 lines of context and line numbers
grep -C 3 -n "search-term" file.txt
Grep multiple patterns with OR
textSearch for multiple patterns (OR condition)
grep -E "(error|warning|critical)" log.txt
Sort and count unique values
textCount frequency and show top 20
sort file.txt | uniq -c | sort -rn | head -20
Xargs parallel execution
textProcess files in parallel with 4 jobs
find . -name '*.log' | xargs -P 4 -I {} gzip {}
Watch command with highlight
systemWatch command every second, highlight differences
watch -n 1 -d 'ps aux | grep process-name'
Check disk IO statistics
systemExtended IO stats, 1-second intervals, 10 times
iostat -x 1 10
Check memory usage details
systemDetailed memory statistics breakdown
vmstat -s | head -20
Check CPU usage per core
systemCPU stats per core, 1-second interval, 5 times
mpstat -P ALL 1 5
Check system load history
systemSystem activity report, CPU usage over time
sar -u 1 10
Check kernel messages
systemShow recent kernel errors
dmesg | grep -i error | tail -20
List open files by user
systemCount open files by specific user
lsof -u username | wc -l
Check network interface stats
networkShow detailed network interface statistics
ip -s link show dev eth0
Monitor file changes in real-time
filesWatch directory for file changes recursively
inotifywait -m -r -e create,modify,delete /path/to/watch
Create swap file
systemCreate and enable 2GB swap file
fallocate -l 2G /swapfile && chmod 600 /swapfile && mkswap /swapfile && swapon /swapfile
Limit process resources
systemSet file descriptor and process limits
ulimit -n 4096; ulimit -u 100; command
Change file permissions recursively
filesSet 644 for files, 755 for directories recursively
find /path -type f -exec chmod 644 {} \; && find /path -type d -exec chmod 755 {} \;
Change ownership recursively
filesChange owner and group recursively
chown -R user:group /path
Create hard and symbolic links
filesCreate both hard link and symbolic link
ln target hardlink; ln -s target symlink
Mount disk image
systemMount ISO file as loop device
mount -o loop disk.iso /mnt/iso; umount /mnt/iso
Generate secure random password
systemGenerate 32-byte base64 encoded random string
openssl rand -base64 32
Base64 encode/decode
textBase64 encode and decode text
echo 'text' | base64; echo 'dGV4dA==' | base64 -d
Calculate MD5/SHA checksums
filesGenerate MD5 and SHA256 checksums
md5sum file.txt; sha256sum file.txt
Create directory tree structure
filesDisplay directory structure (fallback to find if no tree)
tree -d -L 3 /path; find /path -maxdepth 3 -type d | sort
Compare two files
textUnified diff with color highlighting
diff -u file1.txt file2.txt | colordiff
Split large file
filesSplit file into 100MB chunks and rejoin
split -b 100M largefile.tar.gz 'part-'; cat part-* > combined.tar.gz
Stream edit large file
textExtract lines 10001-19999 from large file efficiently
awk 'NR>10000 && NR<20000' huge.log > subset.log
Download file with curl
downloadDownload file and save with original filename
curl -O https://example.com/file.zip
Download with resume support
downloadResume interrupted download
curl -C - -O https://example.com/large-file.iso
Download with custom filename
downloadDownload and save with custom filename
curl -o myfile.zip https://example.com/file.zip
Download following redirects
downloadFollow redirects and download
curl -L -o file.tar.gz https://example.com/download
Download with authentication
downloadDownload with HTTP Basic Auth
curl -u username:password -O https://example.com/protected/file.zip
Download with headers
downloadDownload with custom HTTP headers
curl -H 'Authorization: Bearer TOKEN' -O https://api.example.com/data.json
Download showing progress bar
downloadDownload with progress bar instead of default stats
curl -# -o file.iso https://example.com/file.iso
Download multiple files parallel
downloadDownload multiple files in parallel
curl -Z -O https://example.com/file1.zip -O https://example.com/file2.zip
Check HTTP headers only
downloadFetch HTTP headers without downloading body
curl -I https://www.example.com
POST data with curl
downloadSend POST request with form data
curl -X POST -d 'name=value&foo=bar' https://api.example.com/endpoint
POST JSON with curl
downloadSend POST request with JSON data
curl -X POST -H 'Content-Type: application/json' -d '{"key":"value"}' https://api.example.com/endpoint
Test API endpoint
downloadTest API with response time and status code
curl -s -w '\nHTTP Code: %{http_code}\nTime: %{time_total}s\n' https://api.example.com/health
Download with wget
downloadDownload file using wget
wget https://example.com/file.zip
Download with resume (wget)
downloadResume interrupted download with wget
wget -c https://example.com/large-file.iso
Download to directory
downloadDownload file to specific directory
wget -P /path/to/downloads https://example.com/file.zip
Mirror website with wget
downloadCreate local mirror of website
wget --mirror --convert-links --adjust-extension --page-requisites --no-parent https://example.com/
Download with bandwidth limit
downloadDownload with 200KB/s speed limit
wget --limit-rate=200k https://example.com/large-file.iso
Batch download from file
downloadDownload all URLs listed in file
wget -i urls.txt
Download in background
downloadDownload in background with log file
wget -b https://example.com/large-file.iso -O /var/log/wget.log
View last N lines of log
logsMonitor log file in real-time (follow mode)
tail -f /var/log/nginx/access.log
Search in log file
logsSearch for errors in syslog (case-insensitive)
grep -i 'error' /var/log/syslog | tail -50
Count log entries by pattern
logsCount occurrences of pattern in log
grep -c '404' /var/log/nginx/access.log
View logs by time range
logsExtract log entries between two timestamps
awk '/2024-01-15 10:00/,/2024-01-15 11:00/' /var/log/syslog
Analyze web access by IP
logsShow top 20 IP addresses accessing website
awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -rn | head -20
Find slow requests
logsFind requests taking more than 5 seconds
awk '$NF > 5 {print $0}' /var/log/nginx/access.log | tail -20
Extract HTTP status codes
logsCount HTTP response status codes
awk '{print $9}' /var/log/nginx/access.log | sort | uniq -c | sort -rn
Analyze failed SSH attempts
logsFind IPs with most failed SSH login attempts
grep 'Failed password' /var/log/auth.log | awk '{print $11}' | sort | uniq -c | sort -rn | head -10
Audit user login activity
logsShow recent user login/logout history
last | head -20
Check sudo commands used
logsShow recent sudo commands executed
grep 'COMMAND=' /var/log/auth.log | tail -30
Monitor kernel messages
logsShow recent kernel errors
dmesg | grep -i error | tail -20
Analyze Apache error log
logsCount PHP fatal errors in Apache log
grep -o 'PHP Fatal error.*' /var/log/apache2/error.log | sort | uniq -c | sort -rn
Compress and rotate logs
logsCompress log files older than 7 days
find /var/log -name '*.log' -mtime +7 -exec gzip {} \;
Real-time journalctl monitoring
logsMonitor nginx service logs in real-time
journalctl -u nginx -f
Export journal logs
logsExport last hour logs to file
journalctl --since '1 hour ago' --no-pager > /tmp/recent_logs.txt
Analyze MySQL slow queries
logsAnalyze MySQL slow query log sorted by time
mysqldumpslow -s t /var/log/mysql/slow.log | head -20
No commands found
Try adjusting your search