How to check the size of symbol table of Linux directories?



Linux does this slightly differently than AIX. ( I see you are checking the AIX page above ).

But this is how you do it in Linux.

du --inodes -s /path/to/directory

Usually this requires sudo/root privileges.
 
https://www.ibm.com/docs/vi/aix/7.2?topic=systems-directories

How do I check the size occupied by just the symbol table of a directory? i.e the mapping of file names to inodes?
If you want the size of the directory entries (inside the directory file) based on the directory entry format, then the information here will help: https://www.kernel.org/doc/html/latest/filesystems/ext4/directory.html
It deals with the ext4 filesystem.

The --inodes option in du only provides the number of inodes, not the size of the directory entries that hold that inode information :)

It's probably worth noting that the default directory files are usually allocated 4.0K, as can be seen here:

Code:
[flip@flop ~]$ ls -alh
total 24K
drwxr-xr-x  6 flip flip 4.0K Aug 21 20:26 .
drwxr-xr-x 23 flip flip 4.0K Jul 15 09:55 ..
drwxr-xr-x  3 flip flip 4.0K Aug 27 18:23 directory1
drwxr-xr-x  3 flip flip 4.0K Aug  9 08:06 directory2
drwxr-xr-x  2 flip flip 4.0K Jul 15 09:55 directory3
drwxr-xr-x  2 flip flip 4.0K Aug 21 20:27 directory4
-rw-r--r--  1 flip flip    0 Sep 17 12:33 file

This default is common for home directories, and many system directories, but not all. For example, a listing from the root directory shows some variation with the /dev directory for example, having a directory file of 3.4K, and the /etc directory file of 12K:

Code:
[flip@flop /]$ ls -alh
total 136K
drwxr-xr-x  19 root root 4.0K Sep  9 21:41 .
drwxr-xr-x  19 root root 4.0K Sep  9 21:41 ..
lrwxrwxrwx   1 root root    7 Sep 22  2022 bin -> usr/bin
drwxr-xr-x   4 root root 4.0K Sep 16 22:51 boot
drwxr-xr-x  17 root root 3.4K Sep 17 06:42 dev
drwxr-xr-x 165 root root  12K Sep 17 06:42 etc
<snip>

The respective differences represent the different expected needs to hold information in those directory files, with the /etc directory being quite a bit larger than some others.

As to the actual sizes of any directory file at any time, then it's really a byte count that needs to be done in accordance with the size of the structures which account for all files in the directory, as described in the kernel.org link above.
 
Last edited:
I wonder if it's because of different distro's. But output appears to be different on some commands.

~]# du --inodes -s /root
406 /root

~]# ls -ahl /root
total 7.9M
dr-xr-x---. 1 root root 836 Sep 17 08:09 .
dr-xr-xr-x. 1 root root 192 Apr 18 08:35 ..
-rw-------. 1 root root 1.4K Jan 5 2023 anaconda-ks.cfg
drwxr-xr-x 1 root root 6 Mar 22 09:30 .ansible
drwxr-xr-x 1 root root 276 Aug 29 15:04 .azure
-rw------- 1 root root 19K Sep 16 20:01 .bash_history
-rw-r--r--. 1 root root 18 Jan 19 2023 .bash_logout
-rw-r--r--. 1 root root 141 Jan 19 2023 .bash_profile
-rw-r--r--. 1 root root 429 Jan 19 2023 .bashrc
 
I wonder if it's because of different distro's. But output appears to be different on some commands.

~]# du --inodes -s /root
406 /root

~]# ls -ahl /root
total 7.9M
dr-xr-x---. 1 root root 836 Sep 17 08:09 .
dr-xr-xr-x. 1 root root 192 Apr 18 08:35 ..
-rw-------. 1 root root 1.4K Jan 5 2023 anaconda-ks.cfg
drwxr-xr-x 1 root root 6 Mar 22 09:30 .ansible
drwxr-xr-x 1 root root 276 Aug 29 15:04 .azure
-rw------- 1 root root 19K Sep 16 20:01 .bash_history
-rw-r--r--. 1 root root 18 Jan 19 2023 .bash_logout
-rw-r--r--. 1 root root 141 Jan 19 2023 .bash_profile
-rw-r--r--. 1 root root 429 Jan 19 2023 .bashrc
The size values in your root's home directory certainly differ from those in this debian installation here. The output you provide looks like it is indeed indicating the size of the inode data within the directory file, but I can't confirm that.

On this debian system where the directory files have been allocated the default 4.0K size, there is no indication of the actual number of bytes consumed within that 4K by the inode data:
Code:
[root@flop ~]# ls -alh
total 148K
drwx------  9 root root 4.0K Sep 18 06:31 .
drwxr-xr-x 19 root root 4.0K Sep 17 17:28 ..
-rw-r--r--  1 root root  110 Sep  4 13:46 99-msKey.hwdb
-rw-------  1 root root 7.1K Sep 18 06:31 .bash_history
-rw-r--r--  1 root root  720 Jun 29 11:16 .bashrc
drwx------  3 root root 4.0K Sep 23  2022 .cache
drwx------  3 root root 4.0K Nov 21  2021 .config
-rwxrwxr-x  1 root root  104 Sep 13  2022 disable_ipv6
<snip>

I haven't been able to to get information on the size of the inode data with the ls or du commands on this system. Here is a directory which holds directories:
Code:
[flip@flop ~/lemon/file-exp]$ ls -alh
total 36K
drwxr-xr-x  9 flip flip 4.0K Sep 17 12:55 .
drwxr-xr-x 23 flip flip 4.0K Jul 15 09:55 ..
drwxr-xr-x  2 flip flip 4.0K Sep 17 12:49 anoth
drwxr-xr-x  3 flip flip 4.0K Aug  9 08:06 anoth2
drwxr-xr-x  2 flip flip 4.0K Jul 15 09:55 anoth3
drwxr-xr-x  2 flip flip 4.0K Sep 17 12:53 directory1
drwxr-xr-x  2 flip flip 4.0K Sep 17 12:55 empty1
drwxr-xr-x  2 flip flip 4.0K Sep 17 12:55 empty2
-rw-r--r--  1 flip flip    0 Sep 17 12:33 exfile
drwxr-xr-x  2 flip flip 4.0K Aug 21 20:27 servers

When I use du to try and get the inodes sizes in bytes, du still only provides the number of inodes used:

Code:
[flip@flop ~/lemon/file-exp]$ du -shb --inodes .
du: warning: options --apparent-size and -b are ineffective with --inodes
35

The du man page on this system provides the following:
Code:
--inodes
              list inode usage information instead of block usage
which I take to mean the count of inodes and blocks, and not the size of them. And that's how the option functions on this system.

Perhaps the coreutils package on your system, which holds both the du and ls commands, has been configured differently. Interesting.

In any case, the size of an inode can be seen in the following:
Code:
[root@flop ~]# tune2fs -l /dev/sda4 | grep -i inode
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype needs_recovery extent 64bit flex_bg sparse_super large_file huge_file dir_nlink extra_isize metadata_csum
Inode count:              57368576
Free inodes:              57145761
Inodes per group:         8192
Inode blocks per group:   512
First inode:              11
Inode size:               256
Journal inode:            8
Journal backup:           inode blocks

Then some maths may be needed to calculate the size of the entries in the directory file using info from the linked page in post #4.
 
Last edited:

Members online


Top