Turbocharge your Linux terminal productivity with these 12 tips

pieter

Pieter D

Posted on April 30, 2021

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!

💖 💪 🙅 🚩
pieter
Pieter D

Posted on April 30, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related