Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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

Apologies if this question has already been asked, I couldn't find anything…

Lets say I want to replace 'oldstuff' with 'newstuff'. Basically re-naming to replace. I try using this command:

mv ~/newstuff ~/oldstuff

But that only moves the folder 'newstuff' into the 'oldstuff' folder.

How would I replace 'oldstuff' with 'newstuff'?

I am running OS X 10.7.

share|improve this question
up vote 3 down vote accepted

If ~/oldstuff does not exist,

mv ~/newstuff ~/oldstuff

will rename newstuff to oldstuff. If it exists, it will move newstuff into oldstuff.

So, to answer your question, first remove ~/oldstuff (or rename it to olderstuff, see this question again on how to do it), then use the mv command as you did.

share|improve this answer
    
oldstuff does exist though. That's the issue, is there anyway to do it without issuing a delete command first? – Jacob Wood Jul 24 '13 at 0:01
    
@JacobLukeWood: There cannot be two directories with the same name. If you want to move the contents into an existing directory, use mv newstuff/* oldstuff (could get more complicated if .files are involved). – choroba Jul 24 '13 at 0:27
    
I ended up doing what you said using the wildcard (*) with it, thanks :) – Jacob Wood Jul 24 '13 at 2:16

Another solution would be to use rsync. (Be careful with the trailing slashes. They are important).

This will copy everything in newstuff into oldstuff.

rsync -av ~/newstuff/ ~/oldstuff

And, the code below will copy everything in newstuff into oldstuff, and delete anything in oldstuff which is not in newstuff.

rsync -av --delete ~/newstuff/ ~/oldstuff

Note that neither of these commands will do anything to the files in ~/newstuff though. If you want to delete them, you'll have to do the rm command separately.

share|improve this answer

You have at least two options.

mv ~/newstuff/* ~/oldstuff
rmdir ~/newstuff
mv ~/oldstuff ~/newstuff

and

mv ~/oldstuff ~/ancientstuff
mv ~/newstuff ~/oldstuff
share|improve this answer

You can try:

mv -f folder1/* folder2 && rmdir folder1

Will move everything in folder1, including files and directories to folder2.

-f: do not prompt before overwriting equivalent to --reply=yes.

mv man page.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .