Relative path to source when copying or moving
This should do the trick:
mv long/path/to/a/folder{,.old}
Reference: search for Brace Expansion in bash manpage.
Related videos on Youtube
Comments
-
Alaa Ali over 1 year
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 forlong/path/to/a/
.I know I could of course
cd long/path/to/a/
and thenmv folder folder.old
, but that involves an extra command, and I'll end up in another working directory. -
don.joey almost 11 yearsBeautiful. Is there also an alternative solution with arguments?
-
Eric Carvalho almost 11 years@Private I don't get it. Can you provide an example?
-
Eric Carvalho almost 11 years@Private I don't know if that's possible somehow. Surely it isn't possible using positional parameters ($0, $1, ...).