Disclosure: This article was created or edited with AI assistance. Revised on 13 October 2026 to remove promotional links and unsupported outcome claims. It is educational guidance, not a verified personal case study or a measured result. Examples are illustrative; use only your own documented experience and measurements.
The sections below present options and illustrative examples. Adapt them to the requirements of your project or role; they do not establish a universal rule or promise a result.
1. !! — Repeat Last Command
Forgot sudo? Don't retype the whole thing:
apt install nginx
# Permission denied
sudo !!
# Runs: sudo apt install nginx
Inspect the previous command before rerunning it with elevated privileges.
2. ctrl + r — Reverse Search History
Stop scrolling through your history with the up arrow. Press ctrl + r and start typing. In common Bash/Readline setups, it searches your command history; behavior depends on the shell and configuration.
# Finds: docker compose up -d --build
Press ctrl+r again to cycle through matches.
3. xargs — Turn Output Into Arguments
Preview .log files inside a dedicated sample directory:
# Preview the selected files first; -print0 handles spaces and newlines.
find ./sample-logs -type f -name '*.log' -print0 | xargs -0 -I {} printf '%s\n' '{}'
Avoid piping broad process-name matches into kill. Inspect exact process IDs and understand what they belong to before stopping a process.
4. watch — Run a Command Repeatedly
Monitor a directory for changes every 2 seconds:
watch -n 2 ls -la /tmp/builds/
Watch your API respond in real-time:
watch -n 1 'curl -s localhost:3000/health | jq .'
5. tee — Write to File AND Terminal
See output while also saving it:
npm run build 2>&1 | tee build.log
No more choosing between watching and logging.
6. comm — Compare Two Sorted Files
Find lines unique to each file:
comm -23 <(sort file1.txt) <(sort file2.txt)
-
-23: Lines only in file1 -
-13: Lines only in file2 -
-12: Lines in both
Perfect for comparing dependency lists, configs, or data sets.
7. column -t — Format Output as a Table
Turn messy output into readable tables:
cat data.csv | column -t -s ','
Before:
name,age,city
john,25,NYC
jane,30,LA
After:
name age city
john 25 NYC
jane 30 LA
Bonus: Command Chaining
Know the difference:
| Operator | Meaning |
|---|---|
&& |
Run next only if previous succeeded |
| `\ | \ |
{% raw %};
|
Run next regardless |
make build && make test && make deploy
# Only deploys if build AND test pass
make build || echo 'Build failed!'
# Shows error message only on failure
What's your favorite terminal trick? Share it below!
These examples assume an interactive Bash-like shell. watch, jq and column may need separate installation. column -s is for simple delimiter-separated text, not a complete CSV parser with quoted fields. Redirection and pipelines may have different failure semantics; inspect each command before adapting it.
Top comments (0)