Bash Shell

From Leo's Notes
Revision as of 01:09, 28 September 2015 by Leo (talk | contribs) (Created page with "Bash, short for the '''B'''ourne '''A'''gain '''Sh'''ell, is a popular interactive shell for Unix based systems and is the default for many distributions. This article will g...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
This page was last edited on 28 September 2015, at 01:09.

Bash, short for the Bourne Again Shell, is a popular interactive shell for Unix based systems and is the default for many distributions.

This article will go over some tips and tricks on using Bash interactively. For more information on scripting in Bash, see Bash Scripting.

User Interactive Keys

Here are some keyboard shortcuts when using the interactive shell. These also work under zsh.

Navigation

CTRL + a Go to start of line (Home key)
CTRL + e Go to end of line (End key)
CTRL + b Back one character (left arrow)
CTRL + f Forward one character (right arrow)
ALT + b Back one word (like in vi 'b')
ALT + f Forward one word (like in vi 'w')

Editing

CTRL + d Delete character under cursor (Delete key)
CTRL + h Delete character before cursor (backspace)
ALT - U Converts to uppercase the word ahead of the cursor
ALT - L Converts to lowercase the word ahead of the cursor
CTRL + w Cuts word before cursor to clipboard
CTRL + u Cuts entire line to clipboard
CTRL + y Pastes the contents of the clipboard (un yank)
CTRL + - Undo a change
ALT + r Restores line from history

Previous Command / Arguments

!! Run last command
!xyz Run last command starting with xyz
!* All arguments of the previous command
!$ / ALT + . Last argument of the previous command
!!:p / !xyz:p / !*:p / !$:p Prints instead of executes the command/arguments
^abc^xyz Runs the previous command with 'abc' replaced with 'xyz'

Others

CTRL + l Clears screen
CTRL + q Stops flow / pauses output
CTRL + s Resumes flow / unpauses output

Redirection

2>&1 STDERR to STDOUT &> Redirect both STDERR and STDOUT

See Also