Another approach is to create your own command dedicated for this purpose. This can be done via function which could looks like:
$ function mv-special { mv $1 $2; cd $(dirname $(echo $2-)); }
Where: (1) mv-special
is the function name; (2) the variables $1
and $2
are arguments in the function who will be used by the commands mv
and cd
; (3) $(echo $2-)
adds a wildcat character to the end of the string in var $2
, and fixes the behaviour of dirname
if the variable $2
contains only path; (4) $(dirname $(echo $2-))
will filter only the path from $2
.
According to this answer the function could looks like:
$ function mv-special { mv $1 $2; cd ${2%/*}; }
Where: ${2%/*}
will filter only the path from $2
.
To be available as a command this function must be exported:
$ export -f mv-special
Usage:
$ mv-special file.pdf ../../../Dropbox/sharedfolder/subdirectory/file.pdf
or:
$ mv-special file.pdf ../../../Dropbox/sharedfolder/subdirectory/
Please pay attention to that - for both variants - the second argument ($2
) must finishes with filename or slash (/
).
To be our new command permanently available, the definition of the function and the export command must be appended to ~/.bashrc
:
# My custom 'mv-special' command:
function mv-special { mv $1 $2; cd $(dirname $(echo $2-)); }
export -f mv-special
or:
# My custom 'mv-special' command:
function mv-special { mv $1 $2; cd ${2%/*}; }
export -f mv-special

Custom command can be made and via executable script file which is placed in ~/bin
or in /usr/sbin
: How can I create a custom terminal command (to run a script)? But to be honest, I was faced a trouble with the behaviour of cd
in this scenario.