Linux – How does one inspect the directory structure information of a unix/linux file

filesfilesystemslinux

In Unix file systems directories are just special files with special directory structures that hold the child filename, filename size and inode reference number.

The actual file metadata beyond this is normally stored in the inode itself.

My question is. How does one read the actual special directory structure in its raw form instead of its interpreted form.

Yes I know you can use ls to see the files there. That's not what I am looking for.

Best Answer

The simple answer is that what you want to do is to read the directory file, with a command like cat ., cat /etc, or cat mydir.  Of course, since this is “raw” data, you’d want to use a program that’s better suited to displaying non-ASCII data in a human-friendly way; e.g., hexdump or od.

Unfortunately, as discussed in When did directories stop being readable as files?, most versions of Unix that were released in the past two decades or so don’t allow this.  So the answer to your question may be “find a version of Unix that still allows reading directories”.  AIX, most versions of BSD, and all but the most recent versions of Solaris may qualify.  Finding a Linux that allows it may require the use of a time machine.