Relative path to source when copying or moving [duplicate]
This might be trivial, but here goes.
In terminal, I tend to find myself moving/renaming/copying files that are not in my current working directory instead of cd
-ing to the directory of those files first. For example, I find myself doing:
mv long/path/to/a/folder long/path/to/a/folder.old
Sometimes, this can be a "long/path with spaces/to/a/folder"
.
My question is: is there a way/shortcut for the <target path>
to be relative to the <source path>
? For instance, does something like this exist:
mv long/path/to/a/folder ``/folder.old
Where ``
means "the same path or the same parent path of the file/folder I'm trying to move", so in my example ``
would stand for long/path/to/a/
.
I know I could of course cd long/path/to/a/
and then mv folder folder.old
, but that involves an extra command, and I'll end up in another working directory.
This should do the trick:
mv long/path/to/a/folder{,.old}
Reference: search for Brace Expansion in bash manpage.