Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have used cp -rl to copy a folder. When measuring the size of the source and of the result of the copy du -sl returns slightly different sizes, even though diff confirms that their content are identical:

$ cp -rl folderA/ folderB/
$ du -sl folderA folderB
98561224 folderA
98590512 folderB
$ diff --brief -ra folderA/ folderB/
$

Both folders reside on the same hard drive, no modifications to any of them have been done between the copy and the measure. I found nothing in the documentation of du and cp which could explain the difference.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Just tried this myself, and I found the discrepancy in size is from the directory files. Since they are not hardlinked they are new files that get created, maybe not with the exact same metadata?

To illustrate this run the following commands:

ls -alR folderA/ | grep -v '^d' | awk '{total += $5} END {print "Total:", total}'
ls -alR folderB/ | grep -v '^d' | awk '{total += $5} END {print "Total:", total}'

These sizes should be identical (dir files not included). You could print the listings with the directory sizes and diff the results to find which dirs exactly are different.

share|improve this answer
    
Indeed, the results are identical. –  Laurent Giroud Jul 14 '11 at 21:10
    
I too found that it is the directory files that are different. But why is this? –  oliman Mar 4 '12 at 4:42
    
On linux directories are in fact files themselves, just of a special kind. I'm not truly sure of why there is a difference, but it is likely related to metadata stored by the filesystem. Your original directories may have a larger size because they used to have more files in them, but were removed(?). These removed files added some "padding" to the metadata of the dir file which isn't used anymore. So when the dir is copied there is no need to also copy this now stale data, thus the copies are smaller. P.S. this is total guesswork. If you find out, please respond though. –  Nicholi Mar 5 '12 at 18:18

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.