I have two directories that look something like the following but with many more files.
folder1/pic1.png
folder1/test/readme.txt
folder2/guest.html
folder2/backup/notes.txt
I want to "merge" these two so all the contents of folder2 end up in folder1 and folder2 gets removed. They are on the same filesystem and disk (ext4). I know all of the files are unique, would mv work fine here?
The "rsync" command is useful for this. I do something like this:
rsync -PHACcviuma --copy-unsafe-links --exclude="*~" folder2/ folder1/ && rm -fr folder2
All the flags are documented in the rsync man page; basically rsync won't replace newer files with older ones, and won't bother to copy any files that are duplicated in the destination. Otherwise it will copy things with the original metadata (timestamp, permissions, etc) preserved.
The rsync program will also include "hidden files" (names starting with "."), backups (ending with "~", etc) so I use the --exclude option to skip certain uninteresting file patterns.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments