Level Up Your Command Line Skills
The command line is where productivity happens. These 25 tricks will save you time, reduce errors, and make you a more efficient Linux administrator. Bookmark this page—you'll reference it often.
Navigation and History
1. Jump to Previous Directory
cd - # Toggle between current and previous directory
2. Return Home Instantly
cd # No arguments = home directory
3. Search Command History
Ctrl+R # Reverse search, type to find previous commands
!! # Repeat last command
!$ # Last argument of previous command
4. Fix Typos in Previous Command
^typo^correction # Replace first occurrence
# Example: ^sl^ls
File Operations
5. Create Nested Directories
mkdir -p path/to/deep/directory # Creates all parent dirs
6. Create Multiple Files at Once
touch file{1..10}.txt # Creates file1.txt through file10.txt
7. Backup File with Timestamp
cp file.conf{,.bak-$(date +%Y%m%d)} # Creates file.conf.bak-20260204
8. Move File and Follow It
mv file.txt /new/path/ && cd $_ # Move and cd to destination
Text Processing
9. View Large Files Efficiently
less +F filename # Follow mode like tail -f, Ctrl+C to stop
10. Extract Specific Columns
awk '{print $1, $3}' file.txt # Print columns 1 and 3
cut -d':' -f1 /etc/passwd # Cut by delimiter
11. Count Lines/Words/Characters
wc -l file.txt # Lines only
wc -w file.txt # Words only
12. Find and Replace in File
sed -i 's/old/new/g' file.txt # In-place replace all occurrences
Process Management
13. Run Command Immune to Hangups
nohup long-running-command & # Continues after logout
disown %1 # Disown running background job
14. Kill Process by Name
pkill -f process_name # Kill by pattern match
killall nginx # Kill all by exact name
15. Monitor Process Resources
watch -n 1 'ps aux --sort=-%mem | head' # Top memory users, refresh 1s
Network Utilities
16. Quick Port Check
ss -tulnp | grep :80 # What's using port 80?
lsof -i :3000 # More details about port 3000
17. Download with Progress
curl -# -O https://example.com/file.zip # Progress bar download
18. Test Port Connectivity
nc -zv hostname 22 # Check if SSH port is open
timeout 3 bash -c 'cat < /dev/null > /dev/tcp/host/port' # Bash native
Disk and Storage
19. Find Disk Space Hogs
du -h --max-depth=1 | sort -hr # Largest directories
ncdu / # Interactive disk usage (install ncdu)
20. Find Large Files
find / -type f -size +100M 2>/dev/null # Files over 100MB
Productivity Boosters
21. Run Multiple Commands
cmd1 && cmd2 # Run cmd2 only if cmd1 succeeds
cmd1 || cmd2 # Run cmd2 only if cmd1 fails
cmd1 ; cmd2 # Run both regardless
22. Parallel Execution
cat hosts.txt | xargs -P 4 -I {} ssh {} 'uptime' # 4 parallel SSH commands
23. Watch Command Output
watch -d df -h # Highlight differences each refresh
24. Quick Calculations
echo $((1024 * 1024)) # Bash arithmetic
bc <<< "scale=2; 100/3" # Floating point
25. Create Aliases for Common Commands
# Add to ~/.bashrc
alias ll='ls -la'
alias ..='cd ..'
alias gs='git status'
alias k='kubectl'
alias tf='terraform'
Bonus: Essential Key Combinations
- Ctrl+A - Move cursor to start of line
- Ctrl+E - Move cursor to end of line
- Ctrl+U - Delete from cursor to start
- Ctrl+K - Delete from cursor to end
- Ctrl+W - Delete previous word
- Ctrl+L - Clear screen
- Ctrl+Z - Suspend current process (fg to resume)
Conclusion
These tricks become second nature with practice. Start with a few, use them daily, and gradually expand your repertoire. Your future self will thank you.
Want more? Our Linux command-line eBooks dive deep into shell productivity and advanced techniques.