How to compare the size of two directories?

I want to compare the total size of the two directories dir1and dir2in different file systems, so that if diff -r dir1 dir2returned 0, then the overall dimensions are equal. The command dureturns disk usage, and its option --apparent-sizedoes not solve the problem. Now i'm using something like

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

know the approximation of size dir1. Is there a better solution?

edit: for example, I ( diff -r dir1 dir2returns 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 
+5
source share
2 answers

I can’t know exactly what you want. Maybe you want this? diff <(du -sh dir1) <(du -sh dir2)

+6
source

find -printf, .

find dir1 ! -type d -printf "%s\n" | awk '{sum += $1} END{print sum}'

AWK.

END {OFMT = "%.0f"; print sum}

END {printf "%.0f\n", sum}

.0 , , gawk %d, , %g 3.1.5 ( 3.1.6 ).

gawk:

.       C, 'gawk'       % g.

/ AWK.

+4

All Articles