After years of working with Linux systems, I've discovered several powerful command combinations that significantly boost productivity. These aren't your basic ls
or cd
commands - these are the hidden gems that make Linux truly powerful.
Here are some lesser-known but extremely useful command sequences:
# Quickly find and edit a file
find . -name "*.conf" -exec vim {} +
# Monitor log files in real-time with highlighting
tail -f /var/log/syslog | grep --color -E 'error|warning|critical'
# Create a backup with timestamp
cp important_file{,.bak_$(date +%Y%m%d_%H%M%S)}
Linux's true power lies in its file manipulation capabilities:
# Find and delete empty directories
find . -type d -empty -delete
# Compare two directories visually
diff -qr dir1/ dir2/ | grep -v 'Common subdirectories'
# Securely wipe free space (useful before VM snapshots)
cat /dev/zero > wipefile; sync; rm wipefile
These commands provide deep system insights:
# Show top memory-consuming processes
ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head
# Monitor network connections by process
lsof -i -P -n | grep ESTABLISHED
# Check disk I/O in real-time
iostat -xmdz 1
Some time-saving Bash tricks:
# Quickly create a test file with random data
dd if=/dev/urandom of=testfile bs=1M count=100
# Extract a column from CSV (e.g., 2nd column)
awk -F',' '{print $2}' data.csv
# Count lines of code in a project
find . -name '*.py' | xargs wc -l | sort -nr
Advanced SSH techniques every admin should know:
# Create a persistent SSH connection
ssh -o ControlMaster=auto -o ControlPath=~/.ssh/%r@%h:%p user@host
# Securely copy files through intermediate host
scp -o ProxyCommand="ssh gateway_host nc %h %p" file.txt target_host:/path/
Handle processes like a pro with these commands:
# Run a command immune to hangups (nohup alternative)
setsid command &
# Show process tree with CPU/MEM usage
ps axfo pid,user,pcpu,pmem,args --sort -pcpu
# Kill processes matching a pattern
pkill -f "pattern"
Powerful network troubleshooting commands:
# Find which process is using a port
netstat -tulnp | grep :80
# Continuous ping with timestamp
ping example.com | while read pong; do echo "$(date): $pong"; done
# Test SSL/TLS connection
openssl s_client -connect example.com:443 -servername example.com | openssl x509 -noout -text
When things go wrong, these can save you:
# Recover deleted files (must be done quickly)
grep -a -B100 -A100 "search_text" /dev/sda1 > recovered_file.txt
# Check filesystem without mounting
fsck -n /dev/sda1
# Boot into single-user mode (add to kernel params)
single init=/bin/bash
One of Linux's most powerful features is the ability to chain commands together. Here are some killer combinations:
# Find and process files in one go
find /var/log -name "*.log" -type f -mtime +30 -exec gzip {} \;
# Monitor network connections while filtering output
netstat -tulnp | grep -E '(nginx|apache)'
# Quickly analyze log files
tail -f /var/log/nginx/access.log | awk '{print $1}' | sort | uniq -c | sort -nr
These tools deserve more attention:
# ncdu - NCurses Disk Usage analyzer
ncdu /var
# htop - Interactive process viewer
htop
# ripgrep - Faster grep alternative
rg "error" /var/log/ -n --color=auto
# jq - JSON processor
curl -s https://api.github.com/users/octocat/repos | jq '.[].name'
These commands will save you hours:
# Create a quick server (Python 3)
python3 -m http.server 8000
# SSH tricks
ssh -D 8080 user@example.com # SOCKS proxy
sshfs user@example.com:/remote/path /local/path
# Time command execution
time for i in {1..1000}; do curl -s localhost &>/dev/null; done
# Persistent tmux sessions
tmux new -s mysession
tmux attach -t mysession
Powerful one-liners for various tasks:
# Create a simple HTTP monitor
watch -n 1 "curl -s -o /dev/null -w '%{http_code}' example.com"
# Batch rename files
for file in *.jpg; do mv "$file" "${file%.jpg}_backup.jpg"; done
# Quick directory navigation
cd - # Go to previous directory
pushd /path/to/dir # Save current directory
popd # Return to saved directory
# Generate random password
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1
Essential monitoring commands:
# Show disk I/O activity
iotop -oP
# Monitor memory usage
watch -n 1 free -m
# Check CPU frequency scaling
watch -n 1 "cat /proc/cpuinfo | grep MHz"
# Network bandwidth monitoring
iftop -nNP