echo mv /home/user/Downloads/{foo.bar,../Documents/}
(remove echo
if the result looks good).
Note this generates /home/user/Downloads/../Documents/
as the target path. I deliberately used the string you chose when introducing your "whatever operator": ../Documents/
. But if Downloads
is a symlink then /home/user/Downloads/../
may resolve to something other than /home/user/
; in such case /home/user/Downloads/../Documents/
won't be equivalent to /home/user/Documents/
(Trivia: cd /home/user/Downloads/../Documents/
may be equivalent to cd /home/user/Documents/
. This does not mean mv
will see the paths as equivalent. Compare this answer.)
Usually (or if the symlink could interfere) you would simply use /home/user/Documents/
as the target (and you in fact did). This path does not depend on Downloads
being a symlink or not. For this reason you may prefer the following brace expansion:
echo mv /home/user/{Downloads/foo.bar,Documents/}
Its form does not emphasize the "relative" aspect (while ../
in our first command does, I guess), still it saves you typing /home/user/
again.
Brace expansion is not specified by POSIX. It works in Bash and in few other shells, but not in pure sh
.
After cd
You can simply mv foo.bar ../Documents/
if you cd /home/user/Downloads/
first. Do it in a subshell and the current working directory of the main shell will not be affected:
(cd /home/user/Downloads/ && mv foo.bar ../Documents/)
Notes:
- Thanks to
&&
if cd
fails for whatever reason (e.g. a typo in the path) then mv
won't run.
- Again, if
Downloads
is a symlink then ../Documents/
may be different than /home/user/Documents/
.