Cheatsheet: Productivity-boosting Bash shortcuts

The default Linux Bash shell might, at first, feel like a rather restrictive environment to work in. Many users get stuck on the inability to select text with the mouse, or having to rely heavily on the arrow keys to fix a small issue toward the end of a long command.

The truth is that Bash is actually quite user-friendly—once you know how to control all of its nuances. So, if you’re going to spend any meaningful amount of time on your VPS, maintaining it or installing new services via the command line, you’ll benefit from learning these Bash shortcuts.

First off, let’s just throw all the shortcuts at you, and then follow that up with some more detail on a select few, plus video!

ShortcutAction
Navigation
Ctrl + aGo to the beginning of the line.
Ctrl + eGo to the end of the line.
Alt + fMove the cursor forward one word.
Alt + bMove the cursor back one word.
Ctrl + fMove the cursor forward one character.
Ctrl + bMove the cursor back one character.
Ctrl + xxToggle between the current cursor position and the beginning of the line.
Editing
Ctrl + _Undo! (And, yes, that’s an underscore, so you’ll probably need to use Shift as well.)
Ctrl + xCtrl + eEdit the current command in your $EDITOR.
Alt + dDelete the word after the cursor.
Alt + DeleteDelete the word before the cursor.
Ctrl + dDelete the character beneath the cursor.
Ctrl + hDelete the character before the cursor (like backspace).
Ctrl + kCut the line after the cursor to the clipboard.
Ctrl + uCut the line before the cursor to the clipboard.
Ctrl + dCut the word after the cursor to the clipboard.
Ctrl + wCut the word before the cursor to the clipboard.
Ctrl + yPaste the last item to be cut.
Processes
Ctrl + lClear the entire screen (like the clear command).
Ctrl + zPlace the currently running process into a suspended background process (and then use fg to restore it).
Ctrl + cKill the currently running process by sending the SIGINT signal.
Ctrl + dExit the current shell.
Enter~.Exit a stalled SSH session.
History
Ctrl + rBring up the history search.
Ctrl + gExit the history search.
Ctrl + pSee the previous command in the history.
Ctrl + nSee the next command in the history.

All of these keyboard shortcuts are enabled by Emacs mode in Bash. If you’d like to use Vi shortcuts instead, you can enable that mode and use different shortcuts instead. In addition, most of these are compatible with Zsh as well, although you might find that a few don’t work or require slightly altered shortcuts.

As promised, let’s take a slightly longer dive into some of the more complex shortcuts, particularly the ones that could benefit from some visual reinforcement as to their function.

Ctrl + x + x

Technically, this command is activated by hitting Ctrl + x twice, but it also works to just hold down Ctrl and hit x twice.

This command is particularly useful if you want to quickly hop to the beginning of a lengthy command to fix something at the beginning, and then hop to the end.

Ctrl + _

The magical undo keystroke! If you accidentally delete a character or even a whole word via some of the shortcuts listed above, not all is lost. This even works after deleting a whole line with Ctrl + u, but doesn’t work after you’ve executed the command.

Ctrl + l

Clearing the terminal is less about productivity, perhaps, and more about aesthetics, or starting from a clean slate. Whatever your reason, this simple command will help you keep track of your prompt and put the past behind you.

Ctrl + c

The SIGINT shortcut is, truly, one of the most used shortcuts out there. It will attempt to interrupt the currently running process, and is used frequently to stop commands entered with a typo, or those that appear to have hung up.

The next steps

We hope this is a useful resource as you work to become more proficient in navigating the Linux terminal with ease. Learning all of these shortcuts—or even a select few of them—will take some time, but your efforts won’t go unrewarded.

If you have a favorite Bash shortcut that you’d like to share, we would love to hear it! Let us know the details in the comments and we’ll add it to the list. We hope this will become an ever-growing and ever-improving resource, so we’re always looking for more contributions.

Changelog

  • 2017.07.20:
    • Added exit a stalled SSH sessionexit the current shelledit the current command in your $EDITOR.
    • Added the History section.
  • 2017.07.13: Initial version!