2007-08-25

advanced bash

(from deadman, found on Reddit)

^error^correction : fix and run the previous command

!$ : last word of previous command; /tmp of ls /tmp
note that you can feed this -N values, so !-2$ is the last word of two commands ago.

!* : all args of previous command; cd /tmp of vi cd /tmp

modifiers:
:h dirname
:t basename
:r remove extension
:e extension only
:s substitute
:gs global substitute

ls /tmp/foo/bar.tgz
ls !$:h will then run ls /tmp/foo
ls !-2$:t will run ls bar.tgz
ls !-3$:r runs ls /tmp/foo/bar
ls !-4$:r:t does ls bar
ls !-5$:s/foo/frob/ does ls /tmp/frobb/bar.tgz