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:
- everything is a file. directory is also a file
- ina inode meta data from the file is stored, but the file name is not stored there
- file name is stored in directory data
- the size of the directory, the same one that is shown in ls and defaults to 4Kb, depends on the number of files in the directory and the length of their names
- obviously, the more files, the larger the directory size
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
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.