Fundamentals 9 min read

Unlock Hidden Terminal Tricks Every Developer Should Know

Discover 17 lesser‑known shell shortcuts and commands—from repeating previous commands with !! to quickly navigating lines with Ctrl + a/E—that can dramatically speed up debugging, file management, and workflow for developers across any Unix‑like environment.

Code Mala Tang
Code Mala Tang
Code Mala Tang
Unlock Hidden Terminal Tricks Every Developer Should Know

Most developers know basic terminal commands like cd, ls, pwd, and grep, but the shell offers many hidden features that can save time, fix errors quickly, or aid debugging without extra tools.

This article shares practical but lesser‑known terminal commands that every developer should add to their toolbox, each with an explanation and a simple example.

1. !! → Repeat the previous command

This runs the exact command you just entered, useful when you forgot to prepend sudo.

$ apt-get install curl
Permission denied
$ sudo !!

Using !! saves you from re‑typing the whole line.

2. !$ → Insert the last argument of the previous command

Extracts the final argument from the prior command.

$ mkdir logs
$ cd !$

Here !$ expands to logs, handy when working with newly created files or directories.

3. ^old^new → Quick typo correction

Replaces the first occurrence of old with new in the previous command and re‑executes it.

$ cat fole.txt
$ ^fole^file
$ cat file.txt

This avoids re‑typing the entire command.

4. Alt + . (Mac: Esc + . ) → Cycle through previous arguments

Inserts the last argument of the previous command; pressing again steps back further.

$ vim server_config.yml
$ cat <Alt+.>

The shortcut inserts server_config.yml (or the appropriate argument on macOS).

5. xargs → Convert output to arguments

Passes a list of items to another command, acting like “glue” between commands.

$ ls *.log | xargs rm

All .log files are fed to rm for deletion.

6. tee → View output while saving it

Unlike simple redirection ( >), tee lets you see the output and write it to a file simultaneously.

$ make build | tee build.log

You can monitor the build process while build.log is saved for later debugging.

7. grep -R "pattern" . → Search recursively in files

grep

searches text; the -R flag makes the search recursive.

$ grep -R "TODO" .

This finds every occurrence of “TODO” in the current directory tree, useful for locating configuration or code comments.

8. fc → Edit and re‑run the previous command

Opens the last command in your editor (e.g., vim or nano); after saving, the corrected command runs.

$ fc

Especially handy for long or error‑prone one‑liners.

9. !!:n → Repeat a specific argument from the previous command

$ echo one two three
$ echo !!:2
two

Here !!:2 reuses the second argument (“two”) of the prior command.

10. Ctrl + a / Ctrl + e → Jump to line start/end

Ctrl + a

moves the cursor to the beginning of the line. Ctrl + e moves the cursor to the end of the line.

Much faster than using arrow keys.

11. Ctrl + w / Ctrl + u → Quick deletion

Ctrl + w

deletes the word before the cursor. Ctrl + u deletes everything before the cursor.

These shortcuts are very useful while editing commands.

12. !!:gs/old/new/ → Global substitution in the previous command

Re‑executes the last command, replacing all occurrences of a word.

$ echo world world
$ !!:gs/world/universe/
universe universe

Acts like a quick find‑and‑replace.

13. df -h / du -sh * → Check disk usage

When space is low, these commands show overall and per‑directory usage.

$ df -h   # human‑readable free space
$ du -sh *   # size of each item in the current directory

They help identify which files or folders consume the most space.

14. lsof -i :<port> → Find which process occupies a port

If you encounter “port already in use”, this reveals the owning process.

$ lsof -i :8080

You can then decide whether to kill or restart the process.

15. nc -zv <host> <port> → Test if a port is open

Quickly check service reachability.

$ nc -zv google.com 443

If successful, the 443 (HTTPS) port is reachable.

16. cd - → Return to the previous directory

Switches back to the directory you were in before the last cd command.

$ cd projectA
$ cd ../projectB
$ cd -

It works like an undo for cd.

17. Ctrl + l → Clear the screen instantly

No need to type clear; a single shortcut wipes the terminal clean.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

productivityShellBashterminaldev tools
Code Mala Tang
Written by

Code Mala Tang

Read source code together, write articles together, and enjoy spicy hot pot together.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.