[linux] overwrite files if they're smaller

TheMasterGee

LOMCN Veteran
Veteran
Apr 23, 2003
253
4
115
Maybe not a programming question, maybe someone would suggest a script (which I'm thinking of doing in work tomorrow)

To simplify the situation (it's actually alot bigger than this), have 2 folders (say A & B).

B holds tens of thousands of files, in many many subfolders. However, when the files were copied there, you're not 100% sure that the client computer that copied them, over a share, did the job correctly. It happens that you've seen zero byte files and incorrect file sizes, names are correct tho.

A holds a fraction of the files of B, but you know that they're correct.

What you want to do is to copy files from A to B, ignoring the dates as they're unreliable, overwriting anything that exists if the source file is bigger.

cp has no options to do this. rsync has some options I've looked into, but I can't see that it will 'overwrite if bigger', in trials I've noticed it mainly does different sizes, which is no good here as different could be smaller.

In work tomorrow, I'll be looking to shell something akin to taking the source filename (with part of the path), if doesn't exist in the destination - copy it, if it exists, compare the sizes and copy if source is larger.

.. was hoping someone might know of a cp variant that has this built in. Would be much easier.

TIA.