The command-line interface is where the real magic happens in open-source computing. For enthusiasts, system administrators, and developers alike, mastering the terminal isn’t just about getting work doneāit’s a point of pride. If you wear the badge of a true Linux Dork with pride, you are likely always on the lookout for clever shortcuts, hidden commands, and productivity hacks to streamline your workflow and impress your peers.
Here are ten essential terminal hacks every terminal enthusiast should incorporate into their daily routine.
1. Execute the Last Command as Root with sudo !!
We have all been there: you type out a complex, multi-flag command, hit Enter, and receive the dreaded “Permission denied” error. Instead of hitting the up arrow, navigating to the beginning of the line, and manually typing sudo, simply enter:
The double exclamation mark (known as a “bang-bang”) evaluates to the previous command, running it instantly with elevated privileges.
2. Quickly Return to the Previous Directory
Navigating deeply nested directory structures can quickly become tedious. When you need to jump back to your previous working directory, skip typing out the full path or multiple ../ references. Just use:
cd -
This command acts like a “back button” for your terminal, toggling effortlessly between your current directory and the one you were in immediately prior.
3. Search Command History Interactively with Ctrl + R
Stop pressing the Up arrow fifty times to find that long docker or rsync command you ran three days ago. Press Ctrl + R to open an interactive reverse-search prompt. Start typing any part of the command you remember, and your history will automatically filter to match it. Press Ctrl + R repeatedly to cycle through older matching entries.
4. Reuse Arguments with !$
If you just created a directory or checked the status of a file and now want to interact with it, don’t retype the filename. The variable !$ stores the last argument of the preceding command.
mkdir /var/www/my-new-project
cd !$
This sequence creates the directory and immediately switches into it without repetitive typing.
5. Fix Typos on the Fly with fc
Making a typo in a massive, multi-line bash loop or complex command string can be deeply frustrating. Typing fc (Fix Command) opens your last command in your default system editor (such as Vim or Nano). You can edit the command with full text-editing functionality, save, and exit; the terminal will execute the corrected command immediately.
6. Create Instant File Backups
Before editing a critical configuration file in /etc/, making a quick backup copy is standard best practice. You can perform this quickly using brace expansion:
cp /etc/nginx/nginx.conf{,.bak}
This automatically expands to cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak, saving you from typing long file paths twice.
7. Run Commands Disowned from the Terminal
When running a long-lived process or script from an SSH session, closing the terminal usually kills the process. By placing nohup before your command and & at the end, or by using disown, you ensure the process continues running silently in the background:
nohup python3 long_script.py &
8. Monitor File Changes in Real-Time
Instead of repeatedly running ls -l or opening a log file to check for updates, use the watch command to execute a script or command at specified intervals:
watch -n 1 'ls -la /var/log/syslog'
This updates the terminal view every second, allowing you to monitor system changes in real time.
9. Clear the Screen Without Losing Your Command Line
If your terminal window is cluttered with output but you are halfway through typing a long command, typing clear isn’t an option. Press Ctrl + L instead. This clears the screen buffer while preserving whatever text you currently have typed at the command prompt.
10. Alias Your Most Common Workflows
Take control of your terminal speed by defining custom aliases in your ~/.bashrc or ~/.zshrc file. For instance, replacing repetitive arguments with short keywords saves thousands of keystrokes over time:
alias update='sudo apt update && sudo apt upgrade -y'
alias ll='ls -alF'
Mastering these ten terminal hacks will significantly increase your terminal efficiency and solidify your reputation as a knowledgeable command-line power user. Keep experimenting, customizing your environment, and pushing the boundaries of what you can achieve directly from the shell interface.
