Thursday, May 2, 2024
 Popular · Latest · Hot · Upcoming
310
rated 0 times [  310] [ 0]  / answers: 1 / hits: 601888  / 3 Years ago, tue, july 20, 2021, 11:39:46

I want to move content of a directory within another directory with the same folders.


Here's an example:


I have ./backup which has the directories base and test. Now, I want to move these directories to ./backupArchives.


I use this:


mv ./backup/* ./backupArchives

but I got the error


mv: cannot move './backup/base' to './backupsArchive/base': Directory not empty

I tried using --force, but no luck. Is there a way to move it when folders already exists?


Note: I just want to merge contents, there's no overwriting.


More From » directory

 Answers
6

Though its man page doesn't document it, mv will refuse to rename a directory to another directory if the target directory contains files. This is a good thing in your case because you turn out to want to merge the content of the source into the target, which mv will not do.



Use rsync -a backup/ backupArchives/ instead. After that rm -rf backup/*.



Instead of using rsync, you also can do the classical



(cd backup && tar c .) | (cd backupArchives && tar xf -)


which earns you more geek points.


[#32137] Tuesday, July 20, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ronicod

Total Points: 71
Total Questions: 111
Total Answers: 111

Location: Montenegro
Member since Fri, Dec 10, 2021
2 Years ago
ronicod questions
Thu, Nov 11, 21, 06:26, 3 Years ago
Sun, May 7, 23, 13:57, 1 Year ago
Sun, Jun 26, 22, 06:13, 2 Years ago
Fri, Oct 14, 22, 13:55, 2 Years ago
;