Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

4 Answers

up vote 2 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? –  JacobLukeWood 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 :) –  JacobLukeWood Jul 24 '13 at 2:16
add comment

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
add comment

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
add comment

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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