The bash shell – Linux terminal keyboard shortcuts

Hey!

Recently found out that there are some quite awesome shortcuts available that I’ve missed – extremely useful if you use the bash shell in *Nix.

To see which one you are using you can type ‘chsh’ in a terminal – this will tell you if you are using /bin/bash.

Go try them out! This can speed up your work in the terminal incredibly.

** Updated 2011-04-05 – there are many moooore!
See this little link: http://www.faqs.org/docs/bashman/bashref_93.html#SEC100

You can see the bindings by typing “bind -P”

The easier shortcuts:

Ctrl + A Go to the beginning of the line you are currently typing on. Extremely useful in those scenarios when left/right arrow keys do not work. Same as HOME button.
Ctrl + E Go to the end of the line you are currently typing on. Same as END button.
Ctrl + L Clears the Screen, same as the clear command.
Ctrl + U Clears the line before the cursor position. If you are at the end of the line, clears the entire line.
Ctrl + H Backspace.
Ctrl + R Let’s you search through previously used commands. Hit again to roll through the hits in the history. Searches through .bash_history in the user’s home directory.
Arrowkeys Up/Down Same as CTRL + P and CTRL + N. This will browse through the history. Hit enter to execute the command.
Ctrl + C Kill whatever you are running.
Ctrl + D Exit the current shell – logout.
Ctrl + Z Puts whatever you are running into a suspended background process. You can then use the terminal for something else.
Type ‘fg’ in the terminal to restore the process.
Ctrl + W Delete the word before the cursor.
Ctrl + K Clear the line after the cursor.
Ctrl + T Swap the last two characters before the cursor.
Esc + T Swap the last two words before the cursor.
Alt + F Move cursor forward one word on the current line.
Alt + B Move cursor backward one word on the current line.
Tab Auto-complete files and folder names.
Shift + Page Up / Down Scrolls through terminal buffer.

 

The shortcuts that are a little trickier:

Ctrl + X * In a directory you have two files: awesomeapp1.deb and notawesomebutneededapp4.deb. You want to install both. In debian the program you call is “dpkg -i filename.deb”. If you don’t want to write out all the names, you can type this: dpkg -i *.deb CTRL+x * (first ctrl+x and then press the * on your numpad or * on your normal, like shift+’) and then it will resolve the names so that your command will be “dkpg -i awesomeapp1.deb notawesomebutneededapp4.deb”
Ctrl + X Ctrl + V Prints something like this: GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
Macros CTRL +X ( to start, CTRL +X ) to save. For example: first hit CTRL+x SHIFT+8 (this is on my keyboard layout) – then put in your commands. Everything you type after this is saved in a macro. Then CTRL+X SHIFT+9 to save. Then hit CTRL+x e to run the macro.

Have fun!

2 thoughts on “The bash shell – Linux terminal keyboard shortcuts

    1. guldmyr Post author

      It’s fairly easy to test.

      Wrote a simple bash script that looked like this:

      #!/bin/bash

      i="0"

      while [ $i -lt 50 ]
      do
      date >> /tmp/whileloop
      sleep 5
      let i--
      done

      When it’s running it puts the date into /tmp/whileloop

      If I hit CTRL+Z then nothing enters the file. But as soon as it’s resumed (by typing: “fg”) it starts again.

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.