I am on Mac. However, I use gstat (GNU stat) so my understanding is that behavior should match linux.
I cd to a folder. Then I use gstat --format=%h .. The output is 65.
Next, I use gfind . -maxdepth 1 | wc -l. The output is 64.
I expected the gstat command to return the number of hard links for the folder. But it seems to be returning the number of count of files + folders it contains directly inside of it, + 1 for itself).
I have the following questions:
- How do I get the number of hard links of a folder?
- Do hardlinks work differently for folders than they do for files?
- Is a folder just a special kind of file, or is it entirely different?
- Do folders have an inode?
- Are the inodes of folders in any way connected to the inodes of the files and folders contained within it?
I don't know if this matters, but just in case here are some more specifics about my machine and versions:
- Chip: Apple M1 Max
- macOS: Venture 13.5.2
gstatversion: stat (GNU coreutils) 9.1
mount output (information on my filesystem format):
/dev/disk3s1s1 on / (apfs, sealed, local, read-only, journaled)
devfs on /dev (devfs, local, nobrowse)
/dev/disk3s6 on /System/Volumes/VM (apfs, local, noexec, journaled, noatime, nobrowse)
/dev/disk3s2 on /System/Volumes/Preboot (apfs, local, journaled, nobrowse)
/dev/disk3s4 on /System/Volumes/Update (apfs, local, journaled, nobrowse)
/dev/disk1s2 on /System/Volumes/xarts (apfs, local, noexec, journaled, noatime, nobrowse)
/dev/disk1s1 on /System/Volumes/iSCPreboot (apfs, local, journaled, nobrowse)
/dev/disk1s3 on /System/Volumes/Hardware (apfs, local, journaled, nobrowse)
/dev/disk3s5 on /System/Volumes/Data (apfs, local, journaled, nobrowse, protect)
map auto_home on /System/Volumes/Data/home (autofs, automounted, nobrowse)