I understand that a directory is just a file in unix that contains the inode numbers and names of the files within. How do I take a look at this? I can't use cat or less on a directory, and opening it in vi just shows me a listing of the files...no inode numbers.
相关问题
- Why should we check WIFEXITED after wait in order
- UNIX Bash - Removing double quotes from specific s
- bash delete line condition
- Trying to make a permanent Alias - UNIX
- Generating signed XPI via jpm failed
In the old days - Version 7, System III, early System V - you could indeed open a directory and read the contents into memory, especially for the old Unix file system with 2-byte inode numbers and a limit of 14 bytes on the file name.
As more exotic file systems became more prevalent, the opendir(), readdir(), closedir() family of function calls had to be used instead because parsing the contents of a directory became increasingly non-trivial.
Finally, in the last decade or so, it has reached the point where on most systems, you cannot read the directory; you can open it (primarily so operations such as fchdir() can work), and you can use the opendir() family of calls to read it.
Since this is a programming question (it is a programming question, isn't it?), you should check out the
opendir
,readdir
andclosedir
functions. These are part of the Single UNIX Spec.The
dirent.h
file should have the structure you need, containing at least:See here for the
readdir
manpage - it contains links to the others.Keep in mind that the amount of information about a file stored in the directory entries for it is minimal. The inode itself contains the stuff you get from the
stat
function, things like times, size, owner, permissions and so on, along with the all-important pointers to the actual file content.It looks like the
stat
command might be in order. From the article: