Two different folders, have the same name but they have different filesize. Is there any linux command that can compare two folders and tell me the diff in filesize at the same time?

  • Have you tried du? – gelraen Jan 22 '13 at 10:15

bash alternative for Stephane's answer:

diff -u <(cd dir1 && du -a | sort -k2) <(cd dir2 && du -a | sort -k2)

Both this and Stephane's answer assume that there are no newlines in your filenames.


With zsh and vim, you could do:

vim -d =(cd dir1 && du -a | sort -k2) =(cd dir2 && du -a | sort -k2)

(you can replace vim -d with diff -u or kompare or your preferred text comparison utility).

The =(...) form of command substitution is the same as the <(...) one found in ksh, zsh and bash with the exception that it uses a temporary file instead of a pipe so that it can work with commands that expect a regular file (like vim). For commands that don't have that limitation (like diff), you can use <(...) instead.


The directory is just a mapping between file names and inodes, there are no "files in the directory". You can ask for the size of the files reachable through the directory by the command du(1)). If you are worried about the size of the directory itself (as reported by ls -ld directory), that includes current file names, space that was used by now erased files, padding, and assorted bureaucracy.

If you want to know if the files reachable have the same names/contents, cmp(1) compares two files. Or diff(1) (with the -r flag) compares directories recursively (it is geared at text, though).

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.