Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have two directories that needs to be merged together. Files in these two directories are all large files (>= 500MB).

What I want to archive: For files in source directory: if it doesn't exist in destination directory, mv it to the destination directory (which is fast since we are basically creating a new hard link and unlink the source file); if it exist in destination directory, copy the source file there and remove source file.

The most common way to merge directories in Linux system is to use rsync with --remove-source-files option. But this is slow because it will do copy operation even the destination file doesn't exist.

Any better ideas? Thank you.

share|improve this question
2  
What's wrong with mv? –  Michael Hampton Jan 12 at 20:44

2 Answers 2

up vote 3 down vote accepted

Basically what You described is move files an overwrite destination if exists. So Just move them.

share|improve this answer
2  
I'm too obsessed with the idea of merging directories and didn't realize mv can do the job. Thank you and @Michael Hampton for pointing it out. –  yegle Jan 12 at 20:48

mv options are all about conflict resolution:

Pick one:

-f  force (always overwrite)
-i  interactive (ask whether to overwrite)
-n  no clobber (no overwrite)

And this is good too:

-v  verbose

Otherwise, data can get lost and/or it won't be clear what exactly happened.

mv is also superior on the the same fs because it's just updating directory inodes, the files shouldn't messed with. The other thing is that the larger the operation, there is a greater chance for things to go wrong like soft-errors.

share|improve this answer

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.