size of directory reported by ls

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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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:


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x