Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

3 Answers 3

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

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

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

 
discard

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.