Change directory to target of move operation

If you're using bash, then its history interaction has just the shortcut for this. The word designator for the last argument of the previous command:

!!:$
designates the last argument of the preceding command. This may be shortened to !$.

Combined with a modifier to remove the last pathname component:

After the optional word designator, you can add a sequence of one or more of the valid modifiers, each preceded by a ‘:’.

h
Remove a trailing pathname component, leaving only the head.

So:

$ echo /ab/c/d
/ab/c/d
$ echo !$:h
echo /ab/c
/ab/c

The same shortcut can also be used with zsh.


If you're not changing the filename, you can omit it and mv will add it automatically; this is especially useful when moving multiple files:

mv file.pdf ../../../Dropbox/sharedfolder/subdirectory/

mv *.pdf ../../../Dropbox/sharedfolder/subdirectory/

With the directory as the last argument, you can use !!:$ or !$ as muru's answer describes.
If you're using bash with the usual defaults, you can use Alt+. instead.
(This is the readline insert-last-argument command; bind -p will list all your current bindings.)