The Linux terminal is a powerhouse that gives you complete control over your system. While many users rely on graphical interfaces, true Linux enthusiasts know that the real magic lies in the terminal. From system management to automation, the command line offers unmatched flexibility and speed. However, beyond the common commands like ls, cd, and sudo, there are hundreds of hidden tricks and advanced terminal features that can make your workflow faster, smarter, and even more enjoyable.
In this article, we’ll explore the best Linux terminal tricks you probably didn’t know — from hidden shortcuts and productivity hacks to command-line customization and automation.
1. Use the ‘!!’ Command to Repeat the Last Command
One of the simplest yet most useful tricks in the Linux terminal is using !!. It repeats the last command you executed.
For example:
If you forget to use sudo when running a command, just type sudo !! and it will re-run the previous command with elevated privileges. This trick saves a lot of time and frustration.
2. Use ‘Ctrl + R’ to Search Command History
If you’ve ever found yourself typing the same long command repeatedly, Ctrl + R is your friend.
Pressing Ctrl + R opens a reverse search through your command history. Start typing a few letters, and it will auto-complete with matching commands.
Example:
This shortcut helps you find and execute previously used commands in seconds.
3. Combine Commands Using ‘&&’, ‘||’, and ‘;’
You can chain multiple commands together on one line to make your workflow smoother.
-
command1 && command2→ Runs the second command only if the first succeeds. -
command1 || command2→ Runs the second command only if the first fails. -
command1 ; command2→ Runs both commands regardless of the first command’s result.
Example:
This ensures your system updates only if the first command runs successfully.
4. Use Aliases to Simplify Long Commands
If you often use long or complex commands, you can create an alias.
Example:
Now, you can just type update in the terminal to execute both commands.
To make it permanent, add your alias to the ~/.bashrc or ~/.zshrc file:
Then add the alias line, save, and run:
5. Use ‘!!:n’ and ‘!$’ for Argument Reuse
The !$ symbol repeats the last argument from your previous command, which is great for saving time.
Example:
This will change the directory to myfolder without typing it again.
Similarly, !!:n can recall specific arguments from your last command if it had multiple parameters.
6. Use the ‘history’ Command to See All Your Commands
Typing history shows a numbered list of all previously used commands. You can re-run any command by typing !<number>.
Example:
This executes the command number 105 from your history list.
7. Use ‘watch’ to Monitor Command Output in Real-Time
The watch command repeatedly runs another command at fixed intervals and updates the output.
Example:
This checks your disk space every two seconds. It’s perfect for monitoring system resources or network activity in real-time.
8. Use ‘tldr’ for Simplified Command Help
While the man command provides full documentation, it can be overwhelming. The tldr command (Too Long; Didn’t Read) gives you short and practical examples.
Install it first:
Then run:
It will show you simple usage examples of the tar command, saving you time.
9. Use ‘pbcopy’ and ‘xclip’ to Copy Command Output to Clipboard
You can directly copy terminal output to your clipboard using tools like xclip or xsel.
Example:
Now you can paste it anywhere using Ctrl + V.
10. Use ‘grep’ and ‘less’ Together for Better Searching
When working with large log files, use grep and less together:
You can scroll and search efficiently through filtered results.
11. Use the ‘df’ and ‘du’ Commands for Disk Usage
df -h shows overall disk usage in a human-readable format, while du -sh * lists folder sizes in your current directory.
Example:
This helps you identify large directories quickly.
12. Use ‘curl ifconfig.me’ to Check Your Public IP
To find your public IP address directly from the terminal, run:
It’s a simple and quick way to see your external IP address without opening a browser.
13. Use ‘ncdu’ for an Interactive Disk Usage Viewer
If you want a visual way to see which directories are taking space, install and use ncdu:
It gives you an interactive interface to navigate and delete files directly.
14. Use ‘htop’ Instead of ‘top’
top shows running processes, but htop is a more advanced and user-friendly version.
Install it with:
Then type htop to open a colorful, interactive process manager. You can kill processes, view CPU usage, and sort data easily.
15. Use ‘tree’ to View Directory Structure
tree displays directories and files in a hierarchical tree format.
Install and use:
This makes it easier to visualize directory structures at a glance.
16. Use ‘cal’ to Display a Calendar
The simple cal command shows the current month’s calendar:
To see the entire year, use:
It’s a fun and handy tool for quick date checks.
17. Use ‘uptime’ to See How Long the System Has Been Running
The uptime command displays how long your system has been running since the last reboot:
It also shows average system load for the past 1, 5, and 15 minutes.
18. Use ‘alias’ with Fun Commands
You can even create playful aliases, like:
Now, if you forget to type sudo, just type please and it will rerun your last command with superuser privileges.
19. Use the ‘fortune’ and ‘cowsay’ Commands for Fun
Add some humor to your terminal with fortune and cowsay:
You’ll get a random quote or saying, displayed as if a cow is speaking it.
20. Use ‘curl wttr.in’ to Check the Weather
You can check the weather of any city right in your terminal:
It gives you a neat text-based weather report.
21. Use Tab Autocompletion and Wildcards
The Tab key is one of the most powerful tools in Linux. Press it to autocomplete commands, file names, and directories.
Wildcards like * and ? let you perform actions on multiple files at once.
Example:
This removes all files ending with .log in the current directory.
22. Use ‘rsync’ for Fast File Copying
rsync is much faster and smarter than cp. It can copy files between directories or even remote servers while maintaining permissions and resuming interrupted transfers.
Example:
It’s great for backups and syncing data efficiently.
23. Use ‘!! > file.txt’ to Save Output of Last Command
You can redirect the output of your previous command into a file easily:
This will save whatever your last command printed into output.txt.
24. Use ‘uptime’, ‘free’, and ‘vmstat’ for Quick System Info
-
uptime→ System uptime and load average -
free -h→ Memory usage -
vmstat→ CPU, memory, and I/O statistics
These commands help you monitor your system without installing extra tools.
25. Customize Your Terminal Prompt (PS1)
You can change how your terminal prompt looks by editing the PS1 variable in your .bashrc:
This sets your prompt to show your username, hostname, and current directory. You can even add colors and emojis for style.
26. Use ‘sudo !!’ and ‘sudo !n’ Like a Pro
If you realize you forgot to add sudo after running a command, just type sudo !!.
If you want to run an older command with sudo, use its number from the history command:
This re-runs command number 104 with admin privileges.
27. Use Keyboard Shortcuts to Save Time
Some powerful keyboard shortcuts include:
-
Ctrl + C→ Stop the current command -
Ctrl + L→ Clear the terminal -
Ctrl + A→ Go to the beginning of the line -
Ctrl + E→ Go to the end of the line -
Ctrl + U→ Delete from cursor to start of line -
Ctrl + K→ Delete from cursor to end of line
Mastering these will drastically improve your speed in the terminal.
28. Use ‘yes’ to Automate Confirmations
If a command asks for repeated confirmations, yes can automatically provide input:
It feeds “yes” to all prompts, automating the process.
29. Use ‘rename’ for Bulk File Renaming
You can rename multiple files in one go using:
This changes all .txt files to .bak.
30. Use ‘script’ to Record Terminal Sessions
Want to record everything you do in a session? Use:
It starts recording all commands and outputs. Type exit to stop recording.
31. Use ‘Ctrl + Z’ and ‘fg’ or ‘bg’ to Manage Jobs
You can pause a running job with Ctrl + Z and resume it in the background with bg. To bring it back to the foreground, use fg.
Example:
Your ping will now run in the background.
32. Use ‘history | grep keyword’ to Find Past Commands
If you don’t remember the full command, search your history:
It shows all commands related to SSH.
33. Use ‘find’ to Locate Files
To search for a file in your system:
This recursively searches all folders inside /home.
34. Use ‘chmod +x’ to Make a Script Executable
When creating bash scripts, you must make them executable:
Then run it with:
35. Use ‘uptime -p’ for a Cleaner Display
If you prefer a more readable format of system uptime:
It shows something like “up 3 hours, 25 minutes.”
36. Use ‘sudo !! | tee file.txt’ to Save and View Output
You can both view and save the output of a command simultaneously:
This is perfect for debugging and documentation.
37. Use ‘echo $SHELL’ to Identify Your Current Shell
If you’re unsure whether you’re using Bash, Zsh, or another shell:
This helps when setting up shell-specific configurations.
38. Use ‘df -Th’ to Show Disk Type and Usage
Adding -T shows filesystem types (e.g., ext4, ntfs):
It helps you identify which partitions use which file systems.
39. Use ‘uptime’, ‘uname -a’, and ‘lsb_release -a’ Together
To get complete system info:
This gives system uptime, kernel details, and OS version in one go.
40. Use ‘exit’ or ‘Ctrl + D’ to Close the Terminal Quickly
When you’re done, simply type exit or press Ctrl + D to close your session.
Conclusion
The Linux terminal is not just a command line — it’s a gateway to mastering your system. By learning and using these hidden terminal tricks, you can streamline your workflow, automate repetitive tasks, and feel truly in control of your machine.
Whether you’re a beginner exploring your first commands or an advanced user fine-tuning scripts, these tricks can save you hours and make your Linux experience more powerful and enjoyable.