Is there a simple combination of commands that count the total size of files different between two directory structures?

I am thinking somehow sending the output of diff to du, but am not proficient enough to know how to actually do this.

An example:

   test1.txt   12 bytes   01/01/2000 12:00:00
   test2.txt   12 bytes   01/01/2000 12:00:00
   test3.txt   12 bytes   01/01/2000 12:00:00
 test4.txt   12 bytes   01/01/2000 12:00:00
 test5.txt   12 bytes   01/01/2000 12:00:00

   test1.txt   12 bytes   01/01/2000 12:00:00
   test2.txt   12 bytes   01/01/2000 12:00:05
   test3.txt   35 bytes   01/01/2000 12:00:05
 test6.txt   12 bytes   01/01/2000 12:00:00
 test7.txt   12 bytes   01/01/2000 12:00:00

In the above, comparing the two directories, b over a I would like:

test1.txt: unchanged, same size:      0 bytes
test2.txt: changed, same size:       12 bytes
test3.txt: changed, different size:  35 bytes
test4.txt: unchanged, same size:      0 bytes
test5.txt: deleted:                   0 bytes
test6.txt: hardlink of test4.txt:     0 bytes
test7.txt: added:                    12 bytes

                           total:    59 bytes
  • 1
    I'm not sure I understand. Do you want to i) find all files whose sizes are different in two directories and ii) sum their sizes? Or do you want to find all files that are different between two directories (even if they are the same size) and then sum their sizes? Or do you want the difference in size between the two directories? Please edit your question and clarify. Ideally, add a simple example to illustrate what you need. – terdon Dec 13 '17 at 10:04
  • Added clarification. As you might suppose, this is a question in the domain of setting up an archiving and backup system. Responses in that direction are most welcome. – J Collins Dec 13 '17 at 10:17
  • And do you really need this? Why not just rsync all the things and let it deal with what has changed? I mean, is the information of changed, same size or changed, N bytes important or are you just looking for a way to copy only those files that have changed? – terdon Dec 13 '17 at 10:19
  • The motivation is to find out how many archive copies will fit on an archive drive before starting the job. – J Collins Dec 13 '17 at 10:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.