In Bash, how can I obtain the directory path from the previous command's last argument

Posted by Beaming Mel-Bin on Super User See other posts from Super User or by Beaming Mel-Bin
Published on 2011-11-15T01:53:45Z Indexed on 2011/11/15 1:57 UTC
Read the original article Hit count: 182

Filed under:
|
|
|

I frequently have to do this. For example:

$ vim /etc/pam.d/sudo
$ vim /etc/pam.d/sudo-i
$ cd /etc/pam.d/  # Figure I should just go to the directory

Now, is there a way I could obtain the directory of the last argument when it's a file path?

I'm asking this cause I recently became aware of the $_ variable that has become useful. Was wondering if there's some other commandline fu that might come in handy.

© Super User or respective owner

Related posts about linux

Related posts about command-line