DEV Community

kol kol
kol kol

Posted on

10 Terminal Tricks I Wish I Knew 5 Years Ago

10 Terminal Tricks I Wish I Knew 5 Years Ago

I've been shipping code from the terminal for years. These 10 tricks would have saved me hundreds of hours.

1. ctrl+r — Reverse Search Your History

Stop scrolling through 100 commands. Press Ctrl+R, start typing any part of a past command, and hit enter to run it. On macOS with fish or zsh, it even shows fuzzy matching.

2. !$ — Reuse the Last Argument

Just ran cat /some/really/long/path/to/file.log and now want to tail it? Don't retype:

tail -f !$
Enter fullscreen mode Exit fullscreen mode

!$ expands to the last argument of the previous command.

3. !! — Repeat the Last Command (with sudo)

Forgot sudo? Classic.

!!
Enter fullscreen mode Exit fullscreen mode

Or combine: sudo !!

4. mkdir -p project/{src,tests,docs}/{components,utils}

Create an entire project structure in one line. Brace expansion + -p means nested directories, no && chaining.

5. diff <(cmd1) <(cmd2) — Compare Command Outputs

Need to compare the output of two commands without writing temp files? Process substitution:

diff <(git branch -a | sort) <(git branch -a --list 'origin/*' | sort)
Enter fullscreen mode Exit fullscreen mode

6. xargs -P — Parallel Execution

Got 50 files to process? Don't loop serially:

find . -name "*.jpg" | xargs -P 4 -I {} convert {} -resize 800x {}_small.jpg
Enter fullscreen mode Exit fullscreen mode

-P 4 runs 4 conversions in parallel. Change the number to match your CPU cores.

7. tmux — Your Terminal Multiplexer

Close your laptop, come back tomorrow, everything is still running. Attach, detach, split panes, survive SSH drops.

tmux new -s dev    # Start a session
# Ctrl+B, D to detach
tmux attach -t dev # Reattach
Enter fullscreen mode Exit fullscreen mode

8. history | awk '{print $2}' | sort | uniq -c | sort -rn | head -20

Find out which commands you actually use most. You'll be surprised. Top results are usually cd, git, ls, and npm.

9. ssh -L 8080:localhost:3000 user@server

Forward a remote port to your local machine. Debug a production API on localhost:8080 while it's actually running on the server.

10. watch -n 2 'curl -s http://localhost:3000/health | jq .status'

Poll an endpoint every 2 seconds and show the result. Perfect for watching a deployment come up without refreshing manually.

The Bigger Picture

Terminal mastery isn't about memorizing flags. It's about composing small tools into powerful workflows. Pipes, redirection, process substitution — once you think in streams, the terminal becomes your IDE.

If you want more developer blueprints and practical guides (not blog fluff), check out Codcompass — we've got 2,800+ vetted tutorials covering CI/CD, cloud infrastructure, and modern web development.


What's your favorite terminal trick? Drop it in the comments — I'm always looking to add to the list.

Top comments (0)