Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

'cd !$' is another recent discovery for me, as in:

mv somefile -t /somedir

cd !$ # now you are in /somedir



A more general way to do this is with M-. (Esc-.). This fetches the last argument from the previously entered command. Very handy when you need to apply multiple commands to a file or directory.

Repeat this key combo to fetch the last argument from further back in your command history.

I use this all the time (almost as much as tab completion).


even better (if you are using bash, not sure about other shells) and use

shopt -s histverify

then if you type !$<enter> will replace !$ with /somedir but not hit return, so you could then modify it. Then you could do...

mv somefile -t /somedir

vim !$<enter>/somefile


Try adding this to your .inputrc file

  $if Bash
    Space: magic-space
  $endif
Now the history expansion will be done when 'space' is pressed.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: