问题描述
我知道一个目录只是一个unix中包含inode号和文件名的文件。我该怎么看这个?我不能使用猫或更少的目录,并在vi中打开它只显示我的文件列表... no inode号。
opendir
, readdir
和 closedir
函数。这些是单个UNIX规范的一部分。 #include< sys / types.h>
#include< dirent.h>
DIR * opendir(const char * dirname);
struct dirent * readdir(DIR * dirp);
int closedir(DIR * dirp);
dirent.h
文件应该有您需要的结构至少包含:
char d_name []条目名称
ino_t d_ino文件序列号
请参阅为 readdir
联机帮助页 - 其中包含指向其他人的链接。
请记住,存储在目录条目中的文件的信息量很少。 inode本身包含您从 stat
函数获取的内容,如时间,大小,所有者,权限等等,以及实际文件的所有重要指针内容。
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.
Since this is a programming question (it is a programming question, isn't it?), you should check out the opendir
, readdir
and closedir
functions. These are part of the Single UNIX Spec.
#include <sys/types.h>
#include <dirent.h>
DIR *opendir (const char *dirname);
struct dirent *readdir(DIR *dirp);
int closedir(DIR *dirp);
The dirent.h
file should have the structure you need, containing at least:
char d_name[] name of entry
ino_t d_ino file serial number
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.
这篇关于如何在Unix中读取目录作为文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!