find . -name foo
vi $(!!)
find . -name foo
vi $(!!)
It's the "Event Designators" in the bash manpage for those who are interested.
As I tried to indicate, you should ideally use whichever will make more sense in your history later. If the command you're typing should always be applied to that file, which happened to be the last argument of the previous command this time, then use !$; if the command you're typing should always be applied to the last argument of the previous command, and it just happened to be that file this time, use $_.
% mkdir foo
% chmod g+s !$
% ls -ld !$ # (make sure it's correct)
% cd !$ $ chmod 755 foo
$ cd !$:p
cd foo
$ cd foo
There are some similar "tricks" here:So, when you press ! $ <space>, it expands out to "foo" in place, so you can be sure that's what you wanted, and edit it in place.
I think :p predates magic-space. They're both decades old at this point though.
Are you feeling lucky?
http://geekblog.oneandoneis2.org/index.php/2013/04/03/protip...
hg diff -b <filename>
hg commit -m "comments" !$
I use 'hg st' so much that I've aliased it as 'st'. It's just about muscle memory now.
$ Make me a sandwich
What? Make it yourself
$ sudo !!
Okay