16

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.

9

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.

| 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
12

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.

| improve this answer | |
2

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.

| improve this answer | |
1

You have at least two options.

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

and

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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