Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

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.

share|improve this question

marked as duplicate by Eric Carvalho, Braiam, Warren Hill, Seth, Alvar Nov 29 '13 at 0:11

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

up vote 6 down vote accepted

This should do the trick:

mv long/path/to/a/folder{,.old}

Reference: search for Brace Expansion in bash manpage.

share|improve this answer
Beautiful. Is there also an alternative solution with arguments? – don.joey Jun 12 '13 at 13:54
@Private I don't get it. Can you provide an example? – Eric Carvalho Jun 12 '13 at 14:05
I once saw something like cp /long/path/ $1/ where $1 would be the first argument, but I am really not sure so I was wondering whether you knew of an alternative like that. – don.joey Jun 12 '13 at 14:08
@Private I don't know if that's possible somehow. Surely it isn't possible using positional parameters ($0, $1, ...). – Eric Carvalho Jun 12 '13 at 14:33
OK thanks for the info. – don.joey Jun 12 '13 at 14:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.