20 Essential Linux Terminal Tricks to Supercharge Your Productivity
This guide presents twenty practical Linux command‑line shortcuts—including tab completion, directory navigation, command chaining, history search, log monitoring, and alias usage—that help both beginners and seasoned users work faster, avoid common pitfalls, and boost overall terminal efficiency.
1. Use Tab for Auto‑completion
Press Tab while typing a command to let the shell suggest completions that start with the characters you have entered, e.g., typing cp l then Tab may complete to linuxidc.txt.
2. Switch Back to the Previous Directory
The command cd - returns you to the directory you were in before the last cd. It relies on the OLDPWD environment variable, which is set only after a successful directory change.
3. Return to the Home Directory
Use cd ~ or simply cd to jump to your home directory from anywhere.
4. List Directory Contents Quickly
Many users rely on ls -l, but the shortcut ll (often an alias) provides the same detailed view on most Linux distributions.
5. Run Multiple Commands on One Line
Separate commands with a semicolon: command_1; command_2; command_3. All commands run sequentially without waiting for the previous one to finish.
6. Run the Next Command Only If the Previous Succeeds
Use the && operator: command_1 && command_2. A common example is sudo apt update && sudo apt upgrade, which upgrades only after a successful update.
7. Search Your Command History
Press Ctrl+R to start a reverse incremental search. Type a fragment of a previous command; the shell shows the most recent match. Press Ctrl+R repeatedly to cycle through older matches, and Ctrl+C to exit.
8. Unfreeze a Frozen Terminal
On many Unix‑like systems, Ctrl+S pauses output (freezes the terminal). To resume, press Ctrl+Q.
9. Jump to the Beginning or End of a Line
Use Home / End keys, or the more portable shortcuts Ctrl+A (start of line) and Ctrl+E (end of line).
10. Follow a Log File in Real‑time
Run tail -F <logfile> to continuously display new lines as they are appended, automatically retrying if the file is rotated or recreated.
11. Read Compressed Logs Without Decompressing
Use the z suite: zless, zcat, zgrep, etc., to view or search gzip‑compressed files directly.
zcat linuxidc_log.zip | more12. Use less to Read Large Files
less -N <filename>displays the file with line numbers, allows forward/backward navigation, searching, and does not load the entire file into memory.
13. Reuse the Last Argument of the Previous Command
Type !$ to insert the final argument from the most recent command, e.g., after mkdir newdir you can run cd !$ to change into it.
14. Repeat the Entire Previous Command
Enter !! to execute the last command again. Prefix it with sudo (e.g., sudo !!) to rerun the previous command with elevated privileges.
15. Create Aliases to Fix Typos
Add an alias in ~/.bashrc, e.g., alias gerp=grep, so a misspelled command automatically resolves to the correct one.
16. Copy‑Paste in the Terminal
Typical shortcuts: Ctrl+Shift+C to copy, Ctrl+Shift+V to paste. In some clients, selecting text and right‑clicking also works, and the middle mouse button can paste.
17. Terminate a Running Process
Press Ctrl+C to send an interrupt signal, stopping the current foreground command.
18. Empty a File Without Deleting It
Redirect nothing into the file: > filename. This truncates the file to zero length while keeping the file itself.
19. Find Files Containing Specific Text
Use grep -Pri "search_string" /path/to/dir to recursively search case‑insensitively for a string in all files under a directory.
20. Use Built‑in Help for Any Command
Most commands provide a help page via command --help or by invoking the command without arguments. Example: bc -help displays usage information.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
