2

So...

ls -l --block-size=MB

tells me that directory is one MB

ls -l --block-size=MB directory

tells me there's a 3MB file inside the directory. Shouldn't that make the directory at least 3MB? How can the directory be smaller than its contents?

alec
  • 1,708
  • @steeldriver I think that question is asking about the sizes of the directory entries themselves, but this question, based on the example commands, is asking why the sum of the file sizes in the current directory does not include the sizes of the files in the subdirectories – Eric Renouf May 19 '15 at 02:35
  • An analogy would be a shopping list, which can fit into your pocket, unlike the car load of groceries that the shopping list encompasses (references). – G-Man Says 'Reinstate Monica' May 25 '15 at 05:14

1 Answers1

0

No, because the contents of the first directory itself are only 1MB. If you want something that will sum all the sizes in the directory tree under a directory you want du

ls doesn't recurse into subdirectories as a normal matter of course. It just reports on the things that are directly in the location you are looking at. So in your first directory if you add up all the sizes of just the things directly in that directory it can be less than the sizes of the things in a subdirectory. But ls didn't look in that subdirectory, so doesn't know anything about them when it generates its listing for you.

Eric Renouf
  • 18,431
  • Not as accurate of an answer as the answer for the question this is a duplicate of, but the main point is still there. – cremefraiche May 19 '15 at 02:31
  • I think this is a little different from the possible dupe, because that is asking about the size of the directory entry itself, while the example commands this one ask it seems they are doing a listing of the directory and expecting that it will include the subdirectories. – Eric Renouf May 19 '15 at 02:33
  • Thank you @Eric Renouf, du is apparently what I was expecting ls -l to give. I'll have to look up how to use du sometime as without any parameters the output isn't so great. – alec May 20 '15 at 01:57
  • @alec given the ls you tried, du -sh is probably what you want. It will summarize all the subdirectory sizes into a single value, and make that human readable – Eric Renouf May 20 '15 at 02:01
  • Thanks @Eric Renouf du -sh is what I wanted! – alec May 20 '15 at 12:50
  • I am saying it is not as accurate of an answer because you claim 1MB is the size of the contents of the directory, which is not enitrely accurate. As the other answer points out, the 1024B is the size of the directory contents' metadata, and can be less than 1024B, however is always stored in 1024B chunks. The other answer explains this much more accurately. – cremefraiche May 20 '15 at 19:48
  • @cremefraiche I know that's what you're saying, but that is not what the ls command he ran shows, nor what he was interested in, which is why this question is not a duplicate of that one. They are asking fundamentally different questions – Eric Renouf May 20 '15 at 19:58