20 Essential Linux Terminal Tricks to Boost Productivity
This guide presents twenty practical Linux command‑line shortcuts—including tab completion, directory navigation, command chaining, history search, log monitoring, and alias creation—that help both beginners and experienced users work faster and avoid common pitfalls.
1. Use Tab for Autocompletion
Press Tab while typing a command to auto‑complete file names or commands that start with the entered prefix, e.g., typing cp l then Tab suggests linuxidc.txt.
2. Switch to the Previous Directory
Use cd - to return to the last working directory without re‑typing the full path. The command relies on the OLDPWD environment variable, which is set after a successful cd.
3. Return to the Home Directory
Either cd ~ or simply cd jumps to the user’s home directory, saving a few keystrokes.
4. List Directory Contents Quickly
Instead of ls -l, many distributions provide ll as an alias for a detailed listing.
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 on Success
Use the logical AND operator && to chain commands, e.g., sudo apt update && sudo apt upgrade, which runs the second command only if the first succeeds.
7. Search Command History
Press Ctrl+R and type a keyword to perform a reverse search through the Bash history. Press Ctrl+C to exit.
8. Unfreeze a Stuck Terminal
Press Ctrl+Q to resume output if Ctrl+S has paused the terminal.
9. Jump to Line Start or End
Use Ctrl+A to move to the beginning of the line and Ctrl+E to move to the end, which is often faster than the Home/End keys on laptops.
10. Follow a Log File in Real Time
Use tail -F filename (equivalent to --follow=name --retry) to continuously monitor a log file even if it is rotated or recreated.
11. Read Compressed Logs Without Decompressing
Commands like zcat file.gz | more, zless, or zgrep let you view gzip‑compressed logs directly.
12. Use less for Large Files
less -N filenamedisplays a file with line numbers, searchable navigation, and paging, which is more efficient than cat for large files.
13. Reuse the Last Argument of the Previous Command
The shortcut !$ expands to the final argument of the preceding command; Alt+. cycles through previous arguments.
14. Repeat the Entire Previous Command
Typing !! re‑executes the last command, useful for quickly adding sudo before a command.
15. Create Aliases to Fix Typos
Add an alias such as alias gerp=grep in ~/.bashrc to correct frequent misspellings.
16. Copy and Paste in the Terminal
Select text and right‑click to paste (common in PuTTY).
Select text and middle‑click to paste.
Use Ctrl+Shift+C to copy and Ctrl+Shift+V to paste in most Linux terminals.
17. Terminate a Running Process
Press Ctrl+C to stop the currently executing command.
18. Empty a File Without Deleting It
Redirect nothing into the file: > filename.
19. Find Files Containing Specific Text
Use grep -Pri "search_string" path to recursively search for a pattern, ignoring case.
20. Access Command Help
Most commands provide a help page via command --help (e.g., bc --help), which describes usage and options.
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.
