How to handle Bash command-line

The default interactive shell in Debian is Bourne Again SHell, so it worth to invest some time to at least skim through the available readline key sequences to gain higher proficiency at the command-line.

Navigating the command-line

Line

CTRL+a Move to the beginning of the line
CTRL+e Move to the end of the line

Word

ALT+f Move forward a word
ALT+b Move backward a word

Character

CTRL+f Move forward a character
CTRL+b Move backward a character

Jump to the mark

CTRL+@ Set position mark
CTRL+xx Switch between current position and defined position mark
Jump to the beginning of the line if position mark is not set

Jump to the next character occurrence

Ctrl+] A character is read and cursor is moved to its next occurrence
Ctrl+ALT+] A character is read and cursor is moved to its previous occurrence

Clear screen

CTRL+l Clear screen, but leave the current line at the top

Command-line manipulation

Transpose

CTRL+t Transpose neighbouring characters
ALT+t Transpose neighbouring words

Change case

ALT+u Uppercase characters from cursor position to the end of the word
ALT+l Lowercase characters from cursor position to the end of the word
ALT+c Capitalize current or the following word starting from cursor position

Delete

CTRL+d Delete character under the cursor
ALT+/ Delete all spaces and tabulators around cursor position

Expand

ALT+& Perform tilde expansion at the current word
ALT+$ Expand variable name
ALT+g The word before cursor is treated as a pattern for pathname expansion with an asterisk implictly appended
The matching filename is inserted
CTRL+x * The word before cursor is treated as a pattern for pathname expansion with an asterisk implictly appended
The whole list of matching filenames is inserted
CTRL+x g The word before the cursor is treated as a pattern for pathname expansion without an asterisk implictly appended
The whole list of matching files/directories is displayed
CTRL+ALT+e Expand the line as the shell does

Cut and paste

CTRL+k Cut text from cursor position to the end of the line
CTRL+u
CTRL+x BACKSPACE
Cut text from the beginning of the line to cursor position
CTRL+w
ALT+BACKSPACE
Cut word before cursor position
ALT+d Cut the word after cursor position
CTRL+y Paste stored text
ALT+y Rotate text to paste

Undo

CTRL+_
CTRL+x CTRL+u
Undo last edit operation
ALT+r Revert line to its initial state [undo all changes]

Miscellaneous

CTRL+v TAB Insert a tabulator character
ALT+# Insert a comment at the beginning of the line
Store line in history
CTRL+x CTRL-v Display Bash version

Notes

This list is not meant to be complete, for more information read bash manual page.

Milosz Galazka's Picture

About Milosz Galazka

Milosz is a Linux Foundation Certified Engineer working for a successful Polish company as a system administrator and a long time supporter of Free Software Foundation and Debian operating system.

Gdansk, Poland https://sleeplessbeastie.eu