10 Linux Terminal Hacks
Struggling with Mistakes and Tedious Tasks in the Linux Terminal?
Working in the Linux terminal can sometimes be frustrating. You hit the wrong command, repeat boring tasks, or wish there was a faster way to get things done. The good news? There is a faster way. Here’s how you can level up your terminal skills with smart, time-saving tricks.
Why These Hacks Matter:
- Fix common mistakes instantly
- Automate repetitive actions
- Boost productivity with minimal effort
- Feel more in control of your Linux environment
These 10 Linux Terminal Hacks Will Change the Game
1. Instantly Rerun the Previous Command with sudo
You just ran a command and got hit with the dreaded:
Permission denied
It happens to everyone—you forget to use sudo
. But instead of retyping the entire command, here’s a smarter way to handle it.
✅ Use This Time-Saving Trick:
sudo !!
🔍 What It Does:
!!
is a Bash history expansion shortcut that repeats your last command.- Prefixing it with
sudo
simply reruns the command with elevated privileges.
🧠 Example:
If you typed:
apt update
…and got a permission error, you don’t need to type it again. Just enter:
sudo !!
…and the shell automatically runs:
sudo apt update
🚀 Why It’s Useful:
- Saves time during workflows where you forget
sudo
- Reduces frustration and lets you move on quickly
- Works in most Bash environments, making it universally handy
Start using sudo !!
and you’ll wonder how you ever lived without it.
2. Run Commands Without Leaving a Trace in History
Sometimes, you run a command you’d prefer not to log—maybe it contains sensitive data, a secret token, or it’s just an experiment you don’t want recorded. Luckily, Bash gives you a stealthy way to skip logging specific commands.
✅ The Trick:
Start the command with a space
That’s it. When you prefix a command with a space, Bash won’t save it to your history.
🧪 Example:
echo "This is a secret" # Note the space before 'echo'
🔍 How It Works:
This behavior relies on a Bash environment variable called HISTCONTROL
.
On most Linux systems, HISTCONTROL
is set to either:
ignorespace
: ignores commands that start with a spaceignoreboth
: ignores both duplicates and space-prefixed commands
📝 Check Your HISTCONTROL Setting:
Run this to see your configuration:
echo $HISTCONTROL
If it’s set to ignorespace
or ignoreboth
, you’re good to go. If not, you can set it like this:
export HISTCONTROL=ignoreboth
🔐 Why It’s Useful:
- Protects sensitive data from being stored in history
- Keeps your command history clean during trial and error
- Reduces security risks in shared or logged environments
Use this trick when discretion matters—and keep your terminal history squeaky clean.
3. Fix Typos Instantly Using the Caret (^) Trick
We all make typos—maybe you entered the wrong filename, mistyped a flag, or hit the wrong key while rushing. Instead of retyping the whole command, Bash lets you fix it on the fly with a quick shortcut.
✅ Use This Syntax:
^wrong^right
This tells Bash to:
- Find the first occurrence of the word
wrong
in your previous command - Replace it with
right
- And run the corrected command automatically
🧪 Example:
You accidentally typed:
ping goggle.com
Instead of retyping, just enter:
^goggle^google
Bash will instantly run:
ping google.com
🎯 Key Points:
- Only the first match gets replaced—perfect for single-word typos
- Works in Bash and compatible shells
- Saves time, especially with long or complex commands
⚡ Why You Should Use It:
- Fix common typos in seconds
- Avoid retyping long commands
- Keep your workflow smooth and uninterrupted
Next time you mistype, don’t backspace—just correct and move on with the caret trick.
4. Reuse the Last Argument with Alt + Period (.)
Typing long filenames or directory paths over and over can get tedious—especially when working with deeply nested or complex names. Instead of retyping or copying, you can reuse the last argument from your previous command with a single keyboard shortcut.
✅ The Shortcut:
Press Alt + .
(period)
This inserts the last argument from your previous command at your current cursor location.
🧪 Example 1:
You create a new directory:
mkdir really_long_directory_name_with_underscores
Now instead of typing that long name again to move into it, just run:
cd [press Alt + .]
It becomes:
cd really_long_directory_name_with_underscores
🧪 Example 2:
You extract a file:
tar -xvf archive_name.tar.gz
To remove it after extraction:
rm [press Alt + .]
Bash will auto-fill:
rm archive_name.tar.gz
🔁 Bonus Tip:
- Press Alt + . multiple times to cycle through the last arguments of earlier commands.
⚡ Why It’s Useful:
- Speeds up command chaining
- Reduces repetitive typing
- Works across most Bash-based shells
Start using Alt + .
to eliminate the need to copy, paste, or retype long arguments—it’s a real productivity booster.
5. Create Nested Directories Effortlessly with mkdir -p
Manually creating one directory at a time—especially for nested folders—can be slow and frustrating. Instead of repeating mkdir
for each level, use the -p
flag to create entire directory trees in one go.
✅ Use This Command:
mkdir -p rootfolder/client/components
🔍 What It Does:
- Creates the full directory path in one line
- Automatically creates parent directories if they don’t exist
- Prevents errors if any part of the structure already exists
So instead of:
mkdir rootfolder
cd rootfolder
mkdir client
cd client
mkdir components
You just type:
mkdir -p rootfolder/client/components
🧩 Want Multiple Subdirectories at Once?
You can use brace expansion to create multiple directories under a common root:
mkdir -p rootfolder/{client/components,server}
This command creates:
rootfolder/client/components
rootfolder/server
⚡ Why It’s Useful:
- Saves time setting up project structures
- Reduces repetitive typing
- Keeps your terminal workflow clean and efficient
Use mkdir -p
next time you start a project, and set up your folder hierarchy with one clean command.
6. Freeze and Unfreeze Your Terminal with Ctrl+S and Ctrl+Q
Ever hit Ctrl+S
in the terminal by mistake, trying to save something—only to find your terminal completely unresponsive? Don’t panic. Your system hasn’t crashed, and your keyboard is just fine.
✅ What’s Happening?
Pressing Ctrl+S
sends a flow control signal called XOFF, which tells the terminal to pause output. This freezes your terminal screen, making it look like it’s stuck.
🔓 How to Unfreeze It:
Simply press:
Ctrl + Q
This sends the XON signal, telling the terminal to resume output—and just like that, your terminal is back to normal.
🧠 Why Does This Feature Exist?
- It’s a legacy feature from the days of slow serial communication
- Back then, it helped users pause scrolling text to avoid overflow
- Today, it mostly confuses users who hit
Ctrl+S
out of habit
⚠️ Pro Tip:
If you often hit Ctrl+S
accidentally, consider disabling software flow control:
stty -ixon
This disables the Ctrl+S
shortcut and prevents accidental terminal freezes.
⚡ Why You Should Know This:
- Avoid unnecessary restarts or confusion
- Quickly unfreeze your session and resume work
- Understand what’s really going on behind the scenes
Knowing how to unfreeze your terminal with Ctrl+Q
is a small trick—but it can save you from a big headache.
7. Clear the Terminal Screen Instantly with Ctrl + L
When your terminal gets cluttered with command output, logs, or error messages, it can become hard to focus. Instead of manually typing clear
every time, use a faster shortcut to wipe the screen clean.
✅ The Shortcut:
Ctrl + L
This instantly refreshes your terminal window—no need to type anything.
🔍 How It Works:
Ctrl + L
tells your terminal to redraw the screen, pushing everything above out of view.- Unlike the
clear
command, this method doesn’t erase your scrollback history.
🧠 Why Use Ctrl + L:
- Quickly declutters your screen without losing command history
- Improves focus during long sessions
- Works across most terminals, including Bash, Zsh, and others.
Ctrl + L vs. clear
– What’s the Difference?
- Both clear the screen — they remove visible clutter instantly.
- Ctrl + L keeps your scrollback history intact, so you can scroll up and view previous commands.
-
clear
may erase your scrollback history depending on your terminal emulator. - Ctrl + L is faster—no need to type, just press the shortcut.
- Both work across most shells, including Bash and Zsh, but
Ctrl + L
is generally more efficient during active sessions.
8. Switch Back to the Previous Directory Instantly with cd -
If you often jump between two directories, retyping full paths can become a hassle. Instead, let Bash handle it for you with a simple, powerful shortcut.
✅ Use This Command:
cd -
This command instantly switches you to your previous working directory—just like hitting the back button in your file browser.
🧪 Example:
You start in:
/home/user/projects/website
Then you move to:
cd ~/Downloads
Now, run:
cd -
You’ll jump right back to:
/home/user/projects/website
Run cd -
again, and you’ll return to:
~/Downloads
It’s a Toggle:
- Each time you use
cd -
, Bash toggles between your current and last directory - It’s perfect for editing files in one place and compiling in another
⚡ Why You Should Use It:
- Saves time during frequent directory switching
- Eliminates the need to remember or retype paths
- Works seamlessly in Bash and other common shells
Use cd -
to boost your terminal navigation speed—it’s a small trick with huge impact on your workflow.
9. Run Multiple Commands in One Line Like a Pro
Running several commands one after another? You don’t need to wait and type each separately. Instead, chain them together on a single line using smart Bash operators.
1. Use ;
to Run Commands Regardless of Outcome
The semicolon (;
) lets you run multiple commands consecutively, no matter if the previous one fails or succeeds.
echo "Updating..." ; sudo apt update ; echo "Done!"
- Even if
apt update
fails,"Done!"
will still be echoed. - This is ideal for non-dependent tasks that should run in sequence.
2. Use &&
to Run the Next Command Only If the Previous Succeeds
The double ampersand (&&
) ensures that the next command runs only if the previous one completes successfully.
sudo apt update && sudo apt upgrade
- Here,
sudo apt upgrade
runs only ifapt update
succeeds. - This helps you build reliable workflows that stop on failure.
3. Use ||
to Run the Next Command Only If the Previous Fails
The double pipe (||
) tells Bash to run the next command only if the previous one fails.
sudo apt update || echo "Update failed!"
- Great for debugging or fallback actions.
- You can display a custom error message or trigger an alternative command if something breaks.
🧠 Bonus Tip: Combine Operators for Smart Logic
You can combine &&
and ||
to create conditional command chains:
sudo apt update && echo "Update successful!" || echo "Update failed!"
- If the update succeeds, it echoes a success message.
- If it fails, it echoes a failure message.
⚡ Why You Should Use This:
- Automates sequences of tasks
- Improves Bash scripting logic
- Reduces manual typing
- Gives you control over success/failure outcomes
Mastering ;
, &&
, and ||
will make your command-line workflows smarter, cleaner, and more efficient.
10. Use Your Fingerprint Instead of a Password for Sudo on Linux
Tired of typing your password every time you run sudo
or unlock your screen? If your laptop has a fingerprint scanner, you can skip the typing and authenticate with a touch—saving time without compromising security.
Here’s how to set it up (tested on Ubuntu and its derivatives):
✅ 1. Install the Required Packages
First, install the fingerprint management tools:
sudo apt install fprintd libpam-fprintd
These packages enable your system to enroll and recognize fingerprint scans.
✅ 2. Enroll Your Fingerprint
Next, register your fingerprint:
fprintd-enroll
Follow the on-screen prompts to scan your fingerprint. Make sure the scan completes successfully.
✅ 3. Configure PAM to Use Fingerprint for sudo
Now, edit the PAM (Pluggable Authentication Module) file for sudo
:
sudo nano /etc/pam.d/sudo
At the top of the file, add the following line:
auth sufficient pam_fprintd.so
💡 Why this works: This line tells the system that fingerprint authentication is enough (sufficient) to run sudo commands.
✅ 4. Test It Out
Run any command with sudo
, like:
sudo apt update
Your terminal will now prompt you to scan your fingerprint instead of entering a password.
⚡ Why You Should Use Fingerprint Authentication:
- ✅ Faster than typing passwords repeatedly
- ✅ Still secure, as biometric access is user-specific
- ✅ Streamlines your workflow, especially during development or frequent sudo use
Boost Productivity Even Further with HOMERDP
Mastering these Linux terminal tricks can dramatically improve your speed, precision, and comfort at the command line. Whether you’re managing servers, coding, testing deployments, or simply navigating your system more efficiently—every shortcut saves time and boosts performance.
But why stop there?
If you’re a developer, engineer, student, or sysadmin who regularly works with Linux environments, HOMERDP takes your workflow to the next level.
EXPLORE MORE; Why Gamers and Developers Will Love the New System76 Linux Powerhouse
READ OUR BLOGS