Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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.

share|improve this answer

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.

share|improve this answer

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).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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