Bang Cash (!$)
This is one I use a lot - so much that I sometimes assume everyone knows it.
Using !$ from the shell will expand to the last argument from the previous command.
So, let's say you are looking at a document
$ cat some/really/long/path/to/readme.md
and then you say to yourself, 'self, I need to edit this file.' Bang Cash to the rescue. Just do:
$ vim !$ # expands to vim some/really/long/path/to/readme.md
Or say you are editing a file
$ vim some/really/long/path/to/index.html
and now you want to see it in the browser
$ open !$
Bang! Cash! You are so money and you don't even know it.
Written by Robin Curry
Related protips
15 Responses

I use the alt-. version (esc, . for you Mac people with jacked up alt keys).
Edit: only works in emacs command mode.

Also, I think $_ is a minor improvement since it doesn't require you to hit return a second time.

@seven1m - I think hitting return a second time is necessary in zsh (tab works too). Not necessary in bash. Don't know about other shells.
Also, "Cash Underscore!" just doesn't have the same ring to it. ;)

You can also use !foo
where "foo" is a command (i.e. "git") and bash will look through your history and run the last previous instance of "foo".
Example:
> git ls-files
> vim Gemfile
> bundle
> !git
The last command would run git ls-files
again.

Thanks @jakebellacera. Good one. That reminded me to share this related tip: https://coderwall.com/p/wx-cag

There's a bunch of these "bang arguments":
- !:0 is the previous command name
- !^, !:2, !:3, …, !$ are the arguments of the previous command
- !* is all the arguments
- !$ is the last argument. You can also use $_ to get the last argument of the previous command.
And more, see this good link

great tip! ever try fish shell lets you work with history in a snap http://fishshell.com/

Yeah @davidchase03 - but this won't work in fish

So, sorta like using !! to execute the previous command.
vim fileWithElevatedPermissions
sudo !!

@droppedonjapan - Yep, exactly. See https://coderwall.com/p/wx-cag

I use this all the time. Voted it up 'cause I loved the “Bang! Cash! You are so money and you don't even know it.” line. Also, it's quite useful!

With ZSH you can do more, as usual. For instance select range of params ;)
$ echo p1 p2 p3
p1 p2 p3
$ echo !:2-3
$ echo p2 p3
p2 p3
Also you can do searches and other cool stuff read more http://www.cs.elte.hu/zsh-manual/zsh_6.html#SEC29

Also this tip looks very similar to https://coderwall.com/p/ttvo9g


So brilliant ! Thank you!