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 used cp -rP <dir name> <new dir name> to copy the contents of a directory, including permissions etc from one dir to another. The odd thing is, either du is giving me some strange results or the copy process is eating up extra blocks for some reason.

For example, the directory copied has an MemberNames.txt file. When copied, I get the following for it in the new (copied) directory:

$ du -sk MemberNames.txt
220 MemberNames.txt

$ ls -al MemberNames.txt
-rwxr-xr-x  1 root  wheel  221344 May  4 00:04 MemberNames.txt

Now if I go the original directory and do the same things, I get this:

$ du -sk MemberNames.txt
88 MemberNames.txt

$ ls -al MemberNames.txt
-rwxr-xr-x  1 root  wheel  221344 May  4 00:04 MemberNames.txt

In other words, it looks like the original file, directly above, is showing 88 blocks used and a file length of 221344 bytes, whereas the copied file is eating up 220 blocks and yet still has a length of 221344 bytes.

Either du is reporting something funky, I don't know how to use it or interpret it properly, or the copy operation (cp) is "scattering" the data into many more blocks than I think I need. If I do a diff on the files, there is no difference between them.

Can someone tell me what is happening, and better yet, how I can get cp to stop eating up more blocks than it needs. I'm not adverse to using a different file copy or transfer tool either, I just want to know why the copied directory is eating up almost 50% more space. This is happening to a lot of files, and a du -sk on the new directory (copied) is almost 50% larger than the original, and yet from a content standpoint, everything is identical.

share|improve this question
3  
Are you copying between two different partitions? If so, and the block levels are different, that could be why the numbers are different –  demure May 20 '13 at 2:20
    
They're different drives but the block sizes and file systems are the same. –  The Anonymous One May 20 '13 at 6:57
    
What file system(s) are you using? Perhaps the second drive is much more fragmented and the data has to be spread around more (shot in the dark)? –  terdon May 20 '13 at 14:13
1  
FWIW and in contrast to some of the prior comments, du -k lists kibibytes, not some arbitrary filesystem-dependent block size. Different filesystem block sizes are not the direct cause of this issue. That being said, filesystems are allowed to store files however they want, using however much (or little) space as they deem suitable, and there never is any guarantee that a copied file takes the same amount of storage space as before. There are all sort of filesystem-specific reasons why the copy could take more space, but a good first suspect is that the original file may have been sparse. –  Celada May 20 '13 at 20:18

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.