3

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.

why?

can somebody explain this?

Martin Vegter
  • 69
  • 66
  • 195
  • 326
  • @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 00: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 'SO- stop being evil' 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](https://unix.stackexchange.com/q/495176/18887) proposes *this* question a dupe of *it*, instead of the parent dupe, suggesting that they *are* truly different. – Sparhawk Jan 17 '19 at 22:43
  • The answers to the dup also answer this question. – roaima Jan 17 '19 at 23:21

1 Answers1

2

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:

Thomas Dickey
  • 75,040
  • 9
  • 171
  • 268
  • You might want to edit this question or link back to your [newer answer](https://unix.stackexchange.com/a/495181/85039) 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 '19 at 09:50