Sunday, 1 April 2007

Bash Shell Keyboard Shortcuts For Linux Users

The default shell on most Linux operating systems is called Bash. There are a couple of important hotkeys that you should get familiar with if you plan to spend a lot of time at the command line. These shortcuts will save you a ton of time if you learn them.

Here is the List of Bash Shell Keyboard Shortcuts For Linux Users

  • Ctrl + A - Go to the beginning of the line you are currently typing on

  • Ctrl + E - Go to the end of the line you are currently typing on

  • Ctrl + L - Clears the Screen, similar to 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 - Same as backspace

  • Ctrl + R - Let’s you search through previously used commands

  • Ctrl + C - Kill whatever you are running

  • Ctrl + D - Exit the current shell

  • Ctrl + Z - Puts whatever you are running into a suspended background process. fg restores it.

  • 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

  • Ctrl + W - erase word before cursor

  • Ctrl + Y - to paste it (as in delete and copy) all text in front of the cursor

  • Esc + . (or Esc + Underscore) - Insert Last Argument

  • Ctrl + b - Move back a character

  • Ctrl + f - Move forward a character

  • Ctrl + r - Search the history backwards

  • Ctrl + xx - Move between EOL and current cursor position

  • Ctrl + x @ - Show possible hostname completions

  • Alt + < - Move to the first line in the history

  • Alt + > - Move to the last line in the history

  • Alt + ? - Show current completion list

  • Alt + * - Insert all possible completions

  • Alt + / - Attempt to complete filename

  • Alt + . - Yank last argument to previous command

  • Alt + c - Capitalize the word

  • Alt + d - Delete word

  • Alt + l - Make word lowercase

  • Alt + n - Search the history forwards non-incremental

  • Alt + p - Search the history backwards non-incremental

  • Alt + r - Recall command

  • Alt + t - Move words around

  • Alt + u - Make word uppercase

  • Alt + back-space - Delete backward from cursor

  • Here "2T" means Press TAB twice

  • $ 2T - All available commands(common)

  • $ (string) 2T - All available commands starting with (string)

  • $ /2T - Entire directory structure including Hidden one

  • $ 2T - Only Sub Dirs inside including Hidden one

  • $ *2T - Only Sub Dirs inside without Hidden one

  • $ ~2T - All Present Users on system from "/etc/passwd"

  • $ $2T - All Sys variables

  • $ @2T - Entries from "/etc/hosts"

  • $ =2T - Output like ls or dir

Useful Note that some of these commands may not work if you are accessing bash through a telnet ,ssh session, or depending on how you have your keys mapped.

10 comments:

Andrew Malcolmson said...

How can I reliably paste from the X Primary buffer? Shift+Insert works but only as long as there's no content in the X Clipboard buffer.

John Bell said...

Depends Upon Your "Editor" Mode

These keybindings depend upon your command/history "editing mode". It starts out in "emacs" mode, but can be changed to "vi" mode. (Use "set -o vi" or "set -o emacs".) When in "vi" mode, the command line is in 'insert' mode until you type Escape, then it goes into 'command' mode (just like vi).

You may well wish to set your bash editing mode to match your prefered editor.

Nihar said...

ALT+_num_ - Types the following character _num_ number of times.

pmboren said...

> Andrew Malcolmson said...
> How can I reliably paste from the X Primary buffer?

xclip works pretty well:

http://people.debian.org/~kims/xclip/

For relatively small excerpts I tend highlight with the mouse. Then I paste it using the middle mouse button.

For large ammounts of text, you can use the cat command and pipe the information to a file. Then you can just open that file in your X application of choice.

Andrew Malcolmson said...

pmboren: xclip is exactly what I needed. Thanks!

My own keyboard tip: consider trying zsh instead of bash. All bash shortcuts will work plus tab completion of arguments and options for many common programs.

suwit said...

Thanks for the true article.
The emperor's clothes.
setup linux and rhce

desimo said...

Second that on xclip! I never knew it was there!

Even vim fanatics (that's me) often do not use set -o vi in their shell.

Think of it this way: the command line inside of vim is not even modal; if you want to edit your commands in a modal environment inside of vim you can use 'q:'

Ctrl + W is listed 2x.

BigSmoke said...

Note that most of these shortcuts are actually Readline shortcuts and thus available to all applications that use libreadline. Myself, I've also published a nice table of Bash/Readline keyboard shortcuts in which you might be interested. It's very readable if I may say so myself.

desimo said...
This post has been removed by the author.
schien said...

I'm running Ubuntu in a VMWare. And some shortcuts do not work. For instance the most useful delete word. Instead Esc + d does this. Any idea how to find out where this behaviour gets obscured?