Bash shortcuts

Useful but no well known shortcuts to editing previous commands in bash

!! expands to the last command and all arguments
!* all arguments of the last command, but not the command itself
!$ last argument of the last command
!foo last command beginning with “foo”
!?bar ast command containing “bar”
^foo^bar last command with the first occurrence of “foo” replaced with “bar”
!:gs/foo/bar last command with all occurrences of “foo” replaced with “bar
<any_above>:p print the command but does not execute

Other useful thins

Brace Expansion

cp file.txt{,.bak}

this basically says cp file.txt file.txt.bak

mkdir -p {src,test}/com/eriwen/{data,view}

This will expand every combination so we get  src/com/eriwen/data, src/com/eriwen/view, test/com/eriwen/data, and so forth. Being able to create a template directory structure with one line is a big time saver!

 

Good reference: http://www.eriwen.com/bash/effective-shorthand/