bash command reuse

When you get tired of typing the same argument over and over

Alt + . cycles through previous args

On the command line you can use substitutions like these


> echo 1 2 3 4
# reuse the 3rd argument of previous command
> echo !:3

> ls -l /path/to/really/long/dir
# last command line argument of last command
> cd $_

> echo 1 2 3
# last word on previous command line
> echo !!$

> cd /path/to/really/lonZdirectory/
# reuse prev command by fixing lonZ to long (only works on first occurrence if there is more than one occurrence)
> ^lonZ^long^
# replace all occurrences
> !!:gs/replaceall/withthis/