I understand the size reported by ls corresponds with number of inodes inside the directory, not their actual size.

I have noticed peculiar behavior, when displaying directory size with ls. Here is how to quickly reproduce it:

first create empty directory, the size reported by ls is 4096 (as expected)

mkdir test
ll -d test/
drwx------ 2 root root 4,096  2015-Dec-29  22:22:36  test/

create 10,000 files inside. Size reported is now 167,936

touch test/{1..9999}
ll -d test/
drwx------ 2 root root 167,936  2015-Dec-29  22:23:24  test/

remove all files. Size should decrease back to 4096

rm test/*
ll -d test/
drwx------ 2 root root 167,936  2015-Dec-29  22:23:59  test/

But the size is still reported as 167,936.


can somebody explain this?

marked as duplicate by Sergiy Kolodyazhnyy, Isaac, Thomas, telcoM, Archemar Jan 21 at 13:35

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • @Gilles - I am not asking "what does size of directory mean in ls". I already know that, as I state in the preamble of my question. Your link does not help answer my question. – Martin Vegter Dec 30 '15 at 0:58
  • See my answer in the "duplicate" link as I cannot reply to this question anymore. – schily Dec 30 '15 at 11:36
  • @MartinVegter Read the answers. They do answer that part of the question as well. – Gilles Dec 30 '15 at 13:29
  • Not sure why this is marked as a dupe. One answer might be similar, but the question is quite different. Nominating for reopening. In fact, this other question proposes this question a dupe of it, instead of the parent dupe, suggesting that they are truly different. – Sparhawk Jan 17 at 22:43
  • The answers to the dup also answer this question. – roaima Jan 17 at 23:21

Generally, directory files are not cleaned up - their space usually is small enough (compared to their contents) that it's not effective to do this (particularly when they might grow again). Finding an authoritative answer for this might be hard... Forum comments are easy:

  • You might want to edit this question or link back to your newer answer on my question. In this question, Generally, directory files are not cleaned up since according to the quote on linked thread in the newer answer this behavior is specific to ext3/ext4 filesystems but works in others like xfs. – Sergiy Kolodyazhnyy Jan 19 at 9:50

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