Directory size is not worth our effort

This is completely useless, unnecessary in practical use, but a fun little post about directories in * nix systems. Friday is the same.



At interviews, boring questions about inodes often slip through, all-is-files, to which few can sanely answer. But if you dig a little deeper, you can find curious things.



To understand the post a few points:





And now the interesting part: create a directory with a million files, check the size of the directory, and then wipe all the files and look at the size of the directory.



$ mkdir niceDir && cd niceDir #     ,     2-10  $ for ((i=1;i<133700;i++)); do touch long_long_looong_man_sakeru_$i ; done $ ls -lhd . drwxr-xr-x 2 user user 8.1M Aug 2 13:37 . $ find . -type f -delete $ ls -l total 0 $ ls -lhd . drwxr-xr-x 2 user user 8.1M Aug 2 13:37 .
      
      





As you can see, the size of the directory has not changed, although it would seem :)



You can fix the size of the directory (without deleting) only with fsck (and the -D option) in the unmounted state.



But when I went looking for why this is so, it turned out that 10 years ago this behavior was already discussed in lkml. And according to the developers, the fix is ​​simply not worth the effort.



All Articles