When using the Linux terminal, we often make mistakes. At other times, tasks feel just plain tedious. Fortunately, there are many terminal tricks that help you amend those mistakes and perform the tedious tasks easily. Let’s explore some of those tricks in this guide.
13Run the Previous Command With sudo
We’ve all been there. You type a command, hit Enter, and get a “Permission denied” message. You realize that you forgot to prefix it withsudo. Instead of retyping the whole thing, you may use a neat little trick:
This tells the shell to rerun your last command, but this time, with sudo. The !! symbol is part of Bash history expansion. It expands to the entire previous command. So, if your last command wasapt update, typing!!would effectively runapt update. Andsudo !!becomes:

It’s a real time-saver, especially when you’re deep into a workflow and forget to elevate privileges.
12Run Commands Without Leaving a Trace
Ever run a command you’d rather not have logged in your history? Maybe you’re using a secret token, experimenting with a risky command, or just trying something you’re not sure about. In Bash, there’s a surprisingly simple way to keep a command out of your history. Just start it with a space.
Here’s an example of my command history.
Now, after running a command starting with a space, it won’t get added to the history.
As you’re able to see, that lastecho commandis not to be found. This trick relies on a Bash feature called HISTCONTROL. By default, many systems have HISTCONTROL set to either ignorespace or ignoreboth. These settings tell Bash to ignore commands that start with a space when writing history.

11Use the Argument From the Previous Command
Ever typed out a long file name, then needed to use it again in the next command? Instead of copying and pasting (or retyping,) just hit Alt+period (.) and it will insert the last argument from the previous command right where your cursor is. It works in most Bash shells, and it’s especially handy for commands that work on the same file or directory over and over.
For example, you might issue this command:
Then you could typecdand hit Alt+. to change directories to the one you just made.
Another common situation where you may use this is when you extract a archive file and want to remove it. If you ran this command:

You could just typermand press Alt+. to delete the archive. You can press this shortcut multiple times to cycle through previous arguments from earlier commands.
10Replace a Word With Another One in the Previous Command
We all type fast and mess up sometimes. Perhaps you are using the wrong filename, server name, or have mistyped a flag. Instead of retyping the entire command, Bash gives you a quick correction tool, the caret (^) symbol:
This replaces the first occurrence of “wrong” in your previous command with “right,” and runs the updated command immediately. Let’s say you meant to ping google.com, but typedping goggle.commistakenly. Just do:

Bash will run:
This can be useful when you have a quick typo to fix, and it occurred only once.
9Swap the Characters Before and After the Cursor
If you’re a fast typist, you’ve probably mashed the wrong keys and typed something like:
When you actually wanted to type:
Yes, that’s such a common typo that there’s literally acommand-line joke toolcalled sl that shows a train chugging across your screen.
But instead of hitting backspace, retyping, or reaching for the arrow keys, there’s a quicker fix. Just hit Ctrl+T. It swaps the two characters right around your cursor. Let’s say you typed:

You meant grep. Just place the cursor on the p, hit Ctrl+T, and it becomes:
It’s a tiny trick that feels minor until you catch yourself using it 20 times a day.

8Using Aliases
Let’s face it. Some Linux commands are just long. And when you’re running them often, typing the same flags or full paths gets irritating. Not to mention error-prone. That’s wherealiasescome in. They allow you to create your own command shortcuts, using simple names for more complex or frequently used commands.
You can quickly create an alias like this:
Now you can just runllon the terminal to do the whole thing. Note that this will only be valid for the current terminal session. If you want to create a permanent alias, you’ll have to add it to the ~/.bashrc file and reload it.
7Format Your Output in Columns
On Linux, we often need to work with data in the command line. Sometimes, the output can be quite messy. Luckily, we have the column command. It can turn that chaos into clean, readable tables of data. The column command formats text into neat columns, aligning things nicely based on whitespace or a custom delimiter. It’s perfect when you’re dealing with data like lists, CSV, colon-separated data, etc.
Let’s see a common example. We can normally list the processes on Linux with:

We can format it further using the column command:
This tells column to create a table with aligned columns. When using this command, it’s best if you have predictable input. If your data is wildly inconsistent, the output might still look a bit rough. Moreover, if your delimiter appears in values, it might throw off the formatting.
6Running Multiple Commands Consecutively
Sometimes you want to run several commands back to back. Instead of typing them one at a time and waiting, you can chain them together on a single line. Then, control whether they run unconditionally or only if the previous one succeeds.
The semicolon (;) lets you chain commands so they run one after the other, regardless of success or failure.

In this example, even ifapt updatefails, the finalecho “Done!“still runs.
The && operator, on the other hand, ensures that each command only runs if the one before it succeeds. This is a smarter way to chain commands.
The command after && will only run if the command before it runs successfully. The opposite of && is the || (two vertical bars) operator. When two commands are combined using this symbol, the command on the right will execute only if the command on the left fails. Using && and || helps you debug issues with yourBash scripts.

Typing your password every time you run sudo or unlock your screen? It’s secure, but after doing it multiple times, it starts feeling tedious. If your laptop has a fingerprint reader, you can use it to authenticate instead of typing your password.
These steps are geared towards Ubuntu and derivatives. The steps may vary for other distros.
Add this line at the top:
Run a command with sudo to test the fingerprint. The system will prompt you to scan your fingerprint instead of asking for a password.
4Go to the Previous Directory You Were In
I often find myself jumping back and forth between two directories. Typing the full path repeatedly is annoying. So this neat little trick was a lifesaver for me:
This command sends you to the previous working directory, just like a back button in yourLinux file system. Let’s say you start in:
Then you go to “~/Downloads.” Now, if you run thecd -command, you’re instantly back in “/home/user/projects/website.” And if you run cd - again, you go back to “~/Downloads.”