4 Linux terminal tricks that make boring jobs weirdly satisfying
4 Linux terminal tricks that make boring jobs weirdly satisfying
In the Linux terminal, repetitive tasks can feel tedious, but a few clever tricks can turn them into something oddly satisfying. Here are four practical techniques that are simple to adopt and can save you time every day.
1. Master history expansion and quick search
History expansion lets you repeat or modify prior commands with minimal typing. Use ! to refer to previous commands and Ctrl-R to search your history interactively. Quick examples:
- Repeat the last command: !!
- Run the last command starting with a string: !git
- Search as you type with Ctrl-R, then press Enter to execute the matched command.
Tip: Combine with sudo if needed by typing sudo and then Ctrl-R to reuse a previous command that required elevated permissions.
2. Format and filter output on the fly
Pipes and text processing tools can transform noisy output into something readable in seconds. A few handy patterns:
- Show only the first column and sort it: ls -l | awk '{print $9}' | sort
- Colorize and highlight patterns with grep: grep --color=auto -i "error" /var/log/syslog
- Live-tail a log and extract fields: tail -f /var/log/syslog | awk '{print $1, $2, $5}'
Tip: Use sed for simple substitutions or cut to slice fields when you don’t need full lines.
3. Watch progress without leaving the terminal
For long-running commands, the watch command periodically re-runs a given command and displays the results. It’s great for tracking updates over time:
- Monitor disk usage: watch -n 2 'du -sh /* | sort -rh | head -10'
- Watch a build log for progress indicators: watch -n 5 'grep -m1 -E "build|done" log.txt'
Tip: Use Ctrl-C to stop watching, and reset the view with a quick watch command if needed.
4. Parallelize tasks and save output cleanly
When you have multiple independent jobs, parallel execution can speed things up. GNU parallel or xargs can run tasks concurrently, while tee lets you save output without losing what you see:
- Run multiple checks in parallel: printf "%s\n" server1 server2 server3 | xargs -I {} -P 3 ssh {} "uptime"
- Capture and view while saving: command | tee output.log
Tip: Start with a small number of parallel processes and adjust based on system load to keep things responsive.
कोई टिप्पणी नहीं:
एक टिप्पणी भेजें