Craig Russell

Web n That

I ♡… the web… php… html… css… linux… shell scripting… folding paper… dog walking… sandwiches… being outside… and most of all @vicuol ☺

Bang Bang – Command Recall in Linux

September 28th, 2011

The loveliness that is the Linux shell has buried in it a billion little nuggets of hyper efficiency. I’ve been learning about the bang history commands, which are a great way to save time when running the similar commands over and over (more thorough documentation here).

Repeating Commands

Repeat last command

!!

Repeat last command that started with x

!x

Repeat last command that has the substring x

!?x

Repeat 10th command in the history file

!10

Repeat 10th from last command in the history file

!-10

Fetching Parameters

Fetch parameters from last command

!!*

Fetch first parameter from last command

!!^

Fetch last parameter from last command

!!$

Fetch third parameter from last command

!!3

Modifiers

Repeat last command substituting foo for bar

!!:s/foo/bar/

Print last command without running it

!!:p