What's your favorite Linux terminal trick?

Take our poll or tell us about your favorite terminal trick. Is it a nifty productivity shortcut or a fun Easter egg?
111 readers like this.
The beginning of a new year is always a great time to evaluate new ways to become more efficient. Many people try out new productivity tools or figure out how to optimize their most mundane processes. One area to assess is the terminal. Especially in the world of open source, there are tons of ways to make life at the terminal more efficient (and fun!) with shortcuts and commands. 
We asked our writers about their favorite terminal trick. They shared their time-saving tips and even a fun terminal Easter egg. Will you adopt one of these keyboard shortcuts or command line hacks? Do you have a favorite you'd like to share? Tell us about it by taking our poll or leaving a comment. 
"I couldn't choose a favorite; I use all three of these daily: 
  • Ctrl + L to clear screen (instead of typing "clear").
  • sudo !! to run previous command with sudo privileges. 
  • grep -Ev '^#|^$' <file> will display file content without comments or empty lines."
—Mars Toktonaliev
"For me, if I'm in a terminal text editor and I want to make it go away so I can quickly do something else, I background it with Ctrl + Z, do whatever I need to do, and then bring it back with fg. I will also sometimes do the same thing with top or htop. I can background it, and bring it back anytime I want to check current performance. I don't see backgrounding and foregrounding done in the wild very often, and it can really enhance multitasking on the terminal."
—Jay LaCroix
"Because I tend to do much of the same things at the terminal on a given day, two things are constants in my day:
  • Ctrl + R to reverse search my Bash history for a command that I have already run and wish to do so again
  • Caret substitution is the best as I often do things like sudo dnf search <package name> then if I find a suitable package that way I then do ^search^install to rerun the command replacing the search with install.
Sure these things are basic but so time-saving for me."
—Steve Morris

"My cool terminal trick isn't something I do in the terminal, but which terminal I use. Sometimes I just want the feeling of using an Apple II, or an old amber-on-black terminal. That's when I fire up Cool Retro Term. Screenshots are on the website."

—Jim Hall
"Probably ssh -X to run graphical programs on other machines. Copy/pasting (on some terminal emulators, like gnome-terminal) C-S c and C-S v. I'm not sure if this counts (as it goes graphical in the interesting part, but starts with ssh). Most recently I had a need to log in to another machine but have my kids be able to follow along on the bigger screen from my laptop. This link showed me something I'd never before seen: mirroring the active session from another computer screen on my laptop over the local network (x11vnc -desktop) and being able to control it from both machines at the same time."
—Kyle R. Conway
"You can install Install 'sl' $ sudo apt install sl or $ sudo dnf install sl, and when the command sl is entered at the Bash prompt a text-based steam locomotive moves across the display."
—Don Watkins
What to read next
User profile image.
Opensource.com publishes stories about creating, adopting, and sharing open source solutions. Follow us on Twitter @opensourceway.


I don't know what is considered a "trick", but I would say the use of ! for running a history item and of course !! for the last item.

But my favourite thing about *nix shells is the pipe, it's such a simple yet clever idea.

Using !$ as last parameter changed my terminal life.

the discovery of !$ combination as calling the last parameter of the previous command changed my life.

Before pressing enter in a long command I know I will need again, I type # symbol to start a comment then type a label (like #aaa). This way I can later press 'ctrl-R aaa Enter' to search my command history for that comment and execute the command.

I would say using BASH that ESC + underline is a pretty useful keybinding. It cyckels through the arguments from previous commands so you don't have to type them again.

My favorite "tricks" are shell functions.

Useful, and a ball to name :)

'fluck' is my favorite - just an rsync tool.

What's great...Anyone asks for 'help' I tell them to just fluck it.

...neglected 'alias' @ use and love this too!

Ctrl+D to log off. It means I've done my job 8-)

screen or byobu or tmux or a combo of them...

My favorite trick is to type ctrl-x ctrl-e to open an editor to write a quick script!

Not purely a terminal trick, but I use it from the terminal a lot. Ever notice how much kruft of old little files you have accumulated? Things like test.txt, or testtext.ps or sometimes bizarre names. And so, just in case, you have to go through these and open them to make sure they're not worth keeping.
Here's the trick -- if you are just creating something to try out a process and really don't care about keeping the output, save it to /tmp. You can still use it in the current session on your computer, but whatever you save in the /tmp directory gets wiped out when you reboot -- like having an automatic flush on the commode!

My favorite shell trick is running fish.

Like the all the people that discovered !$, I have loved it ever since - that is until I discovered it's interactive little brother: ALT+. And I never looked back.

ALT+. is to !$ what CTRL+R is to !! - like !$ it will grab the last argument of the previous command, but instead of you needing to run the command to get the replacement (it's nice that the shell echoes back the complete command before running it), on readline enabled shells ALT+. will grab the last argument from the last command and display it in your editing line. If it's not too your liking, hit the combo again to grab the last arg of the command before that, and so on and so on.

For me it is something very simple. Add a space at the start of your command and it won't go into the history file. So simple and keeps your command history clean of thrashing when you forgot what's where and what's what.

Like the people that !$ changed their lives, I also was in love with it and its friend !!, until I found out about ALT+. - on a readline enabled shell (but not on MacOS, because they can't have nice things), it will grab the last argument of the last command, but instead of having your blindly send the command and only then see what you got (it is nice that the shell echoes the complete command back, before running it) - ALT+. put the last argument right there on the command line, and if you don't like what you got, you can hit ALT+. again to get the last argument from the command previous to that.

You can also grab any other numbered argument from the previous command(s), by using ALT+ followed by ALT+.

My favorite command trick is sudo apt-get install kde-plasma-desktop

Whoa whoa whoa..... Ctrl +u is way more than just cancel input. It's cut before cursor. Ctrl +k is cut after cursor. Ctrl+y is to paste last cut text.

Ctrl+backspace is undo last, by far my fav

For me, Ctrl+z and fg was life saving, then Ctrl+u and Ctrl+y became so handy when i realize i need to type some commands befor already typed long command also Ctrl+a with Ctrl+e is boost for editing, as i use so much file transfer over servers scp was the best handy command.
Also I'm in love with !! And !$ and Ctrl+r
During editing with vi as i remember i need to run some stuff :! is for it without leaving vi
Linux shell is so fun to work with!!

`tmux` always, but especially when secure shelling into another machine.

`set -o vi` for vim on the command line instead of emacs.

Brace expansion, hands down. The best kept secret evar... also, 'set -o vi'

I am a big fan of parameter expansion operators already mentioned and processing arbitrary text data using $IFS and set -- arg1 arg2 argn... no need for so much sed & awk in the wild... the shell can do it!

mv prog1.{c,orig}
fping -nAg 172.{{16..18},{29..31}}.0.0/16
dirname() { echo ${1%/*}; }
basename() { echo ${1##*/}; }

ssh -X is not working with my system

Ctrl - R will save you so much time as you cycle through your history, I add in #Labels at the end so I can search a lot quicker.

Creative Commons LicenseThis work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.