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
  • 358
  • 75
  • 236
  • 411

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
  • 76,765
  • 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 '19 at 09:50