🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

25 Linux Terminal Tricks That Will Save You Hours Every Week

25 Linux Terminal Tricks That Will Save You Hours Every Week

The Linux terminal is incredibly powerful, but most users only scratch the surface of what it can do. These 25 practical tricks will transform your daily workflow, save you hours of repetitive work, and make you look like a command-line wizard.

Bookmark this page — you will come back to it again and again.

Keyboard Shortcuts That Change Everything

1. Ctrl+R — Reverse Search Your History

Stop retyping long commands. Press Ctrl+R and start typing any part of a previous command. It searches backward through your history instantly.

# Press Ctrl+R, then type "docker" to find your last docker command
# Press Ctrl+R again to cycle through older matches
# Press Enter to execute, or Ctrl+G to cancel

2. !! — Repeat the Last Command

# Forgot sudo? No need to retype everything
apt update
# Permission denied!
sudo !!
# Runs: sudo apt update

3. !$ — Reuse the Last Argument

mkdir /var/www/mysite
cd !$
# Runs: cd /var/www/mysite

4. Ctrl+A / Ctrl+E — Jump to Start/End of Line

No more holding the arrow key. Ctrl+A jumps to the beginning, Ctrl+E to the end.

5. Alt+. — Insert Last Argument from Previous Command

cat /etc/nginx/nginx.conf
# Now press Alt+. to insert /etc/nginx/nginx.conf
nano Alt+.
# Becomes: nano /etc/nginx/nginx.conf

File and Directory Power Moves

6. Create Nested Directories in One Command

mkdir -p project/{src,tests,docs}/{v1,v2}
# Creates 6 directories at once:
# project/src/v1, project/src/v2
# project/tests/v1, project/tests/v2
# project/docs/v1, project/docs/v2

7. Find Files Modified in the Last Hour

find /var/log -mmin -60 -type f
# All files modified in the last 60 minutes

find / -mtime -1 -type f -name "*.conf" 2>/dev/null
# All .conf files modified in the last 24 hours

8. Quick File Size Overview

# Top 10 largest files in current directory tree
du -ah . | sort -rh | head -20

# Disk usage by directory (1 level deep)
du -h --max-depth=1 /var | sort -rh

9. Compare Two Files Side by Side

diff --color -u file1.conf file2.conf
# Or use sdiff for side-by-side
sdiff file1.conf file2.conf

10. Batch Rename Files

# Rename all .txt files to .md
for f in *.txt; do mv "$f" "${f%.txt}.md"; done

# Add prefix to all files
for f in *.jpg; do mv "$f" "backup_$f"; done

📚 Master the Command Line

Text Processing Superpowers

11. grep with Context

# Show 3 lines before and after each match
grep -C 3 "error" /var/log/syslog

# Count occurrences
grep -c "404" /var/log/nginx/access.log

# Search recursively, show filenames and line numbers
grep -rn "TODO" /var/www/myapp/

12. awk — Extract Specific Columns

# Print the 1st and 4th column of a space-separated file
awk '{print $1, $4}' /var/log/nginx/access.log

# Sum values in column 2
awk '{sum += $2} END {print sum}' data.txt

# Print lines where column 3 is greater than 100
awk '$3 > 100' server_stats.txt

13. sed — Find and Replace in Files

# Replace text in a file (in-place)
sed -i 's/old_domain/new_domain/g' /etc/nginx/sites-available/mysite

# Delete blank lines
sed -i '/^$/d' config.txt

# Insert text at line 5
sed -i '5i\# Added by admin' config.txt

14. Sort and Deduplicate

# Sort unique IP addresses from a log
awk '{print $1}' access.log | sort -u | wc -l

# Top 10 most frequent IPs
awk '{print $1}' access.log | sort | uniq -c | sort -rn | head -10

Process and System Management

15. Find What Is Using a Port

# What process is on port 80?
sudo lsof -i :80
# Or
sudo ss -tlnp | grep :80

16. Run Commands After Disconnect (nohup/screen/tmux)

# Run a long process that survives SSH disconnect
nohup ./long_script.sh &

# Or use tmux (better)
tmux new -s mysession
# Run your commands...
# Press Ctrl+B, then D to detach
# Reconnect later:
tmux attach -t mysession

17. Watch a Command in Real Time

# Refresh every 2 seconds
watch -n 2 'df -h'
watch -n 1 'ss -s'
watch -n 5 'docker ps'

18. Kill Processes by Name

# Kill all processes matching a name
pkill -f "python3 server.py"

# Or find and kill interactively
pgrep -la python
kill -9 12345

19. Check System Resources in One Line

# Quick system overview
echo "CPU: $(top -bn1 | grep 'Cpu(s)' | awk '{print $2}')% | RAM: $(free -h | awk '/Mem/{print $3"/"$2}') | Disk: $(df -h / | awk 'NR==2{print $5}')"

📚 Level Up Your Admin Skills

Networking One-Liners

20. Test Connectivity and DNS

# Quick connectivity test
ping -c 3 google.com

# DNS lookup
dig example.com +short
nslookup example.com

# Check all open connections
ss -tuln

21. Download Files Like a Pro

# Download with progress bar
wget -q --show-progress https://example.com/file.tar.gz

# Resume an interrupted download
wget -c https://example.com/large-file.iso

# Download an entire website for offline reading
wget -r -l 2 -p -k https://docs.example.com/

Productivity Boosters

22. Create Aliases for Frequent Commands

# Add to ~/.bashrc or ~/.zshrc
alias ll='ls -lah --color=auto'
alias gs='git status'
alias dps='docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"'
alias myip='curl -s ifconfig.me'
alias ports='sudo ss -tlnp'
alias update='sudo apt update && sudo apt upgrade -y'

# Reload after editing
source ~/.bashrc

23. Use xargs for Parallel Processing

# Delete all .log files older than 7 days
find /var/log -name "*.log" -mtime +7 | xargs rm -f

# Compress multiple files in parallel
find . -name "*.csv" | xargs -P 4 -I{} gzip {}

24. Quick HTTP Server from Any Directory

# Python 3 (serves current directory on port 8000)
python3 -m http.server 8000

# PHP
php -S 0.0.0.0:8000

25. Chain Commands Intelligently

# Run next command only if previous succeeds
apt update && apt upgrade -y && reboot

# Run next command only if previous fails
ping -c 1 server1 || echo "Server1 is DOWN!"

# Run regardless of success/failure
make build; make test; make deploy

Bonus: The Ultimate .bashrc Additions

# Colored man pages
export LESS_TERMCAP_mb=$'\e[1;32m'
export LESS_TERMCAP_md=$'\e[1;32m'
export LESS_TERMCAP_me=$'\e[0m'

# Better history settings
HISTSIZE=10000
HISTFILESIZE=20000
HISTCONTROL=ignoredups:erasedups

# Auto-correct typos in cd
shopt -s cdspell

# Useful extraction function
extract() {
    case $1 in
        *.tar.gz)  tar xzf $1 ;;
        *.tar.bz2) tar xjf $1 ;;
        *.zip)     unzip $1 ;;
        *.gz)      gunzip $1 ;;
        *.tar)     tar xf $1 ;;
        *)         echo "Unknown format: $1" ;;
    esac
}

Conclusion

These 25 tricks represent a small fraction of what the Linux terminal can do, but they cover the commands and shortcuts you will use most frequently. Print this page, practice a few each day, and within a week they will become muscle memory.

The terminal is not just a tool — it is a superpower. The more comfortable you become with it, the faster and more efficient your work becomes.

Share this article:

Stay Updated

Subscribe to our newsletter for the latest tutorials, tips, and exclusive offers.