10 Terminal Commands I Wish I Knew 5 Years Ago
For about five years I used the terminal like a very expensive notepad. I typed every command out by hand. I pressed the up arrow 30 times to find something I ran yesterday. I Googled "how to kill process on port 3000"
For about five years I used the terminal like a very expensive notepad.
I typed every command out by hand. I pressed the up arrow 30 times to find something I ran yesterday. I Googled "how to kill process on port 3000" so many times that Google probably autocompletes it for me by now.
None of the commands below are secret. Most of them have existed for decades. But nobody sat me down and showed me, so I learned them one embarrassing moment at a time.
The rule for this list: each one has to kill something I used to retype, re-scroll or re-Google every week. If it's just "cool", it didn't make the cut.
Works in bash and zsh on macOS and Linux unless I say otherwise.
1. Ctrl + R: search your command history
Stop hammering the up arrow.
Press Ctrl + R and start typing any part of a command you ran before:
(reverse-i-search)`dock': docker compose up -d --build
Press Ctrl + R again to cycle through older matches. Enter runs it, → (right arrow) puts it on the line so you can edit first.
This one alone probably saves me 10 minutes a day. That long docker or ssh command you ran last Tuesday? It's three keystrokes away.
2. cd -: jump back to where you were
cd ~/projects/api/src/routes
cd /var/log
cd - # back to ~/projects/api/src/routes
cd - # back to /var/log
It's the "previous channel" button for your terminal. Perfect when you're bouncing between a project folder and a config or log folder.
3. sudo !! and !$: reuse the last command
You've done this:
apt install htop
# Permission denied
Instead of retyping the whole thing:
sudo !!
!! means "the entire last command". And its little sibling !$ means "the last argument of the last command":
mkdir -p src/components/forms
cd !$ # cd src/components/forms
Once these are in your fingers, you'll use them without thinking.
4. fc: edit the last command in your editor
You just typed a 200-character curl command with headers and a JSON body, and it has a typo somewhere in the middle.
fc
This opens the last command in your $EDITOR (vim, nano, VS Code, whatever you set). Fix it, save, close, and it runs. No more holding the left arrow key for 15 seconds.
Tip: export EDITOR="code --wait" if you want it to open in VS Code.
5. lsof -i :3000: who is using my port?
The classic:
Error: listen EADDRINUSE: address already in use :::3000
Find out what's holding it:
lsof -i :3000
And kill it in one line:
lsof -ti :3000 | xargs kill
-t prints only the process ID, which is exactly what kill wants. (Add -9 to kill only if it refuses to die.) I have this aliased as killport now.
6. du -sh * | sort -h: what is eating my disk?
Your laptop says the disk is full. Where did it go?
du -sh * | sort -h
4.0K README.md
12M src
1.8G node_modules
6.3G .docker-cache
-s gives one total per item, -h makes it human-readable, and sort -h sorts those human sizes correctly (so 1.8G comes after 12M). Run it in your home folder once. You'll find something you forgot about.
7. rg (ripgrep): search code ridiculously fast
rg "TODO"
rg "useEffect" --type ts
rg -i "api_key" -g '!node_modules'
It's like grep -r, but much faster, and it skips .gitignored files (like node_modules) by default. Output is grouped by file, with line numbers and highlighting.
Install: brew install ripgrep or apt install ripgrep.
8. fzf: fuzzy-find anything
fzf takes any list and turns it into an interactive, searchable menu.
vim $(fzf) # pick a file, open it
git checkout $(git branch | fzf) # pick a branch, switch to it
The real win: after you install its shell integration, it upgrades your Ctrl + R (from #1) into a fuzzy, full-screen history search, and Ctrl + T drops a fuzzy-picked file path right onto your command line.
Install: brew install fzf, then follow the one-line shell setup it prints.
9. jq: read JSON like a human
API responses come back as one giant unreadable line. Pipe them into jq:
curl -s https://api.github.com/repos/cli/cli | jq '.stargazers_count'
cat users.json | jq '.[] | {name, email}'
Just jq '.' on its own pretty-prints and colors any JSON. I use that version ten times a day.
10. xargs: turn output into arguments
xargs takes the output of one command and feeds it as arguments to another. This is where the terminal starts to feel like a superpower.
Delete every local git branch that's already merged into main:
git branch --merged main | grep -vE '^\*|main$' | xargs git branch -d
Find and delete every .DS_Store in a project:
find . -name ".DS_Store" -print0 | xargs -0 rm
(-print0 and -0 handle file names with spaces safely.)
Read the first example slowly once. List branches → filter out the current one and main → delete the rest. Three small tools, one job. That's the whole Unix philosophy in one line.
Bonus round
-
tldr tar: likeman, but just the 5 examples you actually need. (brew install tlrcornpm i -g tldr) -
Ctrl + A/Ctrl + E: jump to the start / end of the line.Ctrl + Uclears everything before the cursor,Ctrl + Wdeletes one word. -
pbcopy/pbpaste(macOS):cat id_ed25519.pub | pbcopyputs your SSH key on the clipboard. On Linux,xcliporwl-copydo the same.
The real lesson
None of these made me a "10x developer". What they did was remove friction. Every retyped command, every Google search for the same port error, every 30 presses of the up arrow is a tiny context switch that pulls you out of the actual problem.
Automate the boring repetition, so your attention goes to the parts that need a human. That's the idea behind most good tools, and it's what we're trying to do with xenition too. But you can start with Ctrl + R tonight.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.