Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare the size of two directories?

I want to compare the total size of two directories dir1 and dir2 on different file-systems so that if diff -r dir1 dir2 returns 0 then the total sizes will be equal. The du command returns the disk usage, and its option --apparent-size doesn't solve the problem. I now use something like

find dir1 ! -type d |xargs wc -c |tail -1

to know an approximation of dir1's size. Is there a better solution?

edit: for example, I have (diff -r dir1 dir2 returns 0: they are equal):

du -s dir1 --> 540
du -s dir2 --> 166

du -sb dir1 --> 250815 (the -b option is equivalent to --apparent-size -B1)
du -sb dir2 --> 71495

find dir1 ! -type d |xargs wc -c --> 62399
find dir2 ! -type d |xargs wc -c --> 62399 
like image 817
rafak Avatar asked Sep 22 '10 12:09

rafak


1 Answers

i can't know what you want clearly. Maybe you want this?
diff <(du -sh dir1) <(du -sh dir2)

like image 150
zjhui Avatar answered Oct 11 '22 02:10

zjhui