Skip to content

Instantly share code, notes, and snippets.

@ctgardner
Last active June 10, 2023 04:59
Show Gist options
  • Save ctgardner/47ce32afb15d5b3efc0b956b29688496 to your computer and use it in GitHub Desktop.
Save ctgardner/47ce32afb15d5b3efc0b956b29688496 to your computer and use it in GitHub Desktop.
Useful Bash Commands

Prompt Manipulation

Cursor Movement

Move the cursor to Destination.

Command Destination
Ctrl + a Start of line
Ctrl + e End of line
Alt + b Start of word
Alt + f End of word

Ctrl + xx: Start of line (and back again)

Token Deletion

Delete everything between the current cursor position and Destination.

Command Destination
Ctrl + u Start of line
Ctrl + k End of line
Ctrl + w Start of word
Alt + d End of word

Command History

Listing and searching

Command Description
history List all entries
history 3 List last 3 entries
Ctrl + r Search history (or next result)
Ctrl + s Previous search result

Expansion

Command Description
!123 Command #123
!! Last command
!-2 Second-last command
!ssh Last command beginning with ssh
!?ssh Last command ending with ssh
!?ssh? Last command containing ssh
!123:0 Token [0] of command #123
!!:0 Token [0] of last command
!-2:0 Token [0] of second-last command
!!:1* Tokens [1] to [size-1] of last command
!!:1-$ Tokens [1] to [size-1] of last command
!!:* Tokens [1] to [size-1] of last command

^foo^bar^: Replace foo with bar in last command and execute

Sources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment