DEV Community

Cover image for Turbocharge your Linux terminal productivity with these 12 tips
Pieter D
Pieter D

Posted on

Turbocharge your Linux terminal productivity with these 12 tips

The Linux terminal is an incredibly powerful tool to get stuff done quickly. How fast can you go? That greatly depends on how much hotkeys and other power user tricks you know. Here are 12 tips to add to your arsenal.

For details and visual demos, see video below. Read on for the text version.

  1. Let your terminal type filenames for you. Whenever you're typing the name of a file, folder or command, only type a little bit of it and press Tab. Your shell will try to figure out what you're after and complete the name for you. If multiple matches exist, Tab again to see the options, type a few more characters, then Tab once more.
  2. Quickly jump between words. Forgot to add a flag at the start of your command? Alt+Left and Alt+Right let you do word jumps.
  3. Faster backspacing. If you need to erase a part of your command, pressing Backspace is kinda slow. Alt+Backspace erases one word at a time.
  4. Repeating past commands. Ctrl+R allows you to easily recall commands you've done before. Hit the shortcut, then type a part of a past command, then Enter once you see it.
  5. Go back a directory. Entering cd - will bring you right back into the directory you were in before your last cd command. Similarly, you can jump back to your previous Git branch with git checkout -.
  6. Split your terminal. You can have multiple shell prompts on your screen at the same time using Terminator (easiest, mouse-based) or tmux (more powerful, keyboard-based).
  7. Alias long commands. Often need to repeat a long command? Create an alias for it so that you can just execute myAlias next time. Details in the video. An alias looks like alias myAlias="echo Hello world!".
  8. Send output to clipboard. On X with xclip installed, you can pipe any output to xclip -selection clipboard to send it to your system clipboard. Bonus points if you alias it for quick access. Say goodbye to tedious manual text selection!
  9. Make reusable functions. If you want to create an alias but some of its parameters should be variable, this is what you need. A Bash function looks like this:

    function resizeToWidth() {
        convert -resize $1 $2 $2.$1w.png
    }
    

    Once defined, it works like a regular command, e.g. resizeToWidth 500 myImage.png.

  10. Get automatic suggestions. Thanks to the Zsh plugin zsh-autosuggestions your terminal can suggest commands you've previously used as you type – even if you forgot to press Ctrl+R. You can accept suggestions with the Right arrow, or just keep typing if it's not the command you need.

  11. Let your terminal prompt display your current Git branch. Many Zsh themes like robbyrussel's will add an indication of your current Git branch name to your prompt if you're in a Git repository. You won't need git status as much and you'll be less likely to commit to the wrong branch.

  12. Syntax highlighting. You already know syntax highlighting from your IDE, but you can also get that in your shell. This is very useful if you're typing up a command that uses strings, variables or advanced features that go beyond your average ls ~/Desktop. It also shows a visual difference between commands that exist and commands that don't.

What productivity tricks do you use? Share your tips in the comments!

Top comments (6)

Collapse
 
pbnj profile image
Peter Benjamin (they/them) • Edited

Nice post.

My workflow is similar.

Alt+Left and Alt+Right let you do word jumps

Alt-b and Alt-f achieve the same (move cursor back or forward one word at a time)

Bonus: Ctrl-a (move cursor to beginning of prompt) and Ctrl-e (move cursor to end of prompt)

Alt+Backspace erases one word at a time.

Also, Ctrl-w

Bonus: Ctrl-k (delete everything from cursor to beginning) and Ctrl-u (delete everything from cursor to end)

Lastly, I don't know about zsh, but in bash, if you press Ctrl-x + Ctrl-e, you can edit bash commands in $EDITOR before running/executing the command

Collapse
 
pieter profile image
Pieter D

Always good to have more options! I suppose that keystrokes with letters are easier to reach for most people.

Also, I'm happy to confirm that your Ctrl+X -> Ctrl+E tip also works in Zsh here. Thanks Peter!

Collapse
 
dmuth profile image
Douglas Muth

Alt+Backspace erases one word at a time.

So does ctrl-w :-)

I found that if I ever want challenge mode in bash, I'll just type set -e!

Collapse
 
tim_higgins_988c2fc6e77b3 profile image
Tim HIGGINS

What about the old and true set -o vi, this puts your command line in vi mode. I can easily recall a lengthy command with esc k ( puts me into command mode) then / , or if I want to edit a word three words in I type 3w, cw, then type the new word. I find this much easier to use than the standard conventions taught in Linux today. It seems to be a forgotten art. I can do it in less keystrokes. w moves you over one word at a time and b moves you back on word at a time. You can use ^ to get to the start of a line and $ to get to the end of the line. I could go on and on it’s very efficient.

Collapse
 
pieter profile image
Pieter D

I'm very much a fan of vim hotkeys! But while I've tried set -o vi before, for some reason it felt a bit off for me.

I do like what Peter Benjamin suggested, which is to hit Ctrl+X -> Ctrl+E to send your current command to a real vim buffer for editing. That way I get a full vim experience in the editing environment I'm used to, and only when I explicitly request it.

Anyhow, it's great that both options exist. More choice means everyone's free to pick what suits their workflow!

Collapse
 
zilti_500 profile image
Daniel Ziltener

I can also highly recommend Konsole.