Getting dir name or only a file name from a long path is also pretty handy when you use rsync or scp / ssh and friends
Code:
rsync /nas/a/x/y/foo/bar.txt root@server1:/dest/to/path
No I want only dir name
Code:
rsync -a !!:1:h !!:2
Get filename but leaving the dir:
Code:
cp /path/to/logn/dir/foofilenameverylongfilename.txt /mnt/floppy
oh no foofilenameverylongfilename.txt is in current dir:
and the best one find and replace arg:
Code:
scp user@server1:/path/to/alongdir1/file.txt user@server2:/dest
on no dir1 must be dir2:
Code:
scp !!:1:s/dir1/dir2 !!:2
FYI, they are called history modifiers.