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?

  • @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 2: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 5:14

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.

| improve this answer | |
  • 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 2: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 2: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 1: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 2:01
  • Thanks @Eric Renouf du -sh is what I wanted! – alec May 20 '15 at 12:50

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