Replace existing folder with mv command
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.
Solution 1:
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.
Solution 2:
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.
Solution 3:
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.
Solution 4:
You have at least two options.
mv ~/newstuff/* ~/oldstuff
rmdir ~/newstuff
mv ~/oldstuff ~/newstuff
and
mv ~/oldstuff ~/ancientstuff
mv ~/newstuff ~/oldstuff