Sergiy Kolodyazhnyy Asked: 2018-09-10 16:06:10 +0800 CST2018-09-10 16:06:10 +0800 CST 2018-09-10 16:06:10 +0800 CST 如何列出当前目录中的文件及其 inode 编号? 772 如何在当前工作目录中获取项目列表及其 inode 编号? command-line files inode 2 个回答 Voted Best Answer Sergiy Kolodyazhnyy 2018-09-10T16:07:19+08:002018-09-10T16:07:19+08:00 ls有-i标志: $ ls -i 1054235 a.out 1094297 filename.txt 但是,如果您喜欢冒险,请建立ls -i自己: #include <dirent.h> #include <stdio.h> #include <sys/stat.h> #include <unistd.h> #include <limits.h> void print_dirents(DIR * dir){ struct dirent *entry; while ( (entry=readdir(dir)) != NULL ){ printf("%s,%d\n",entry->d_name,entry->d_ino); } } int main(){ char current_dir[PATH_MAX]; DIR *cwd_p; if ( getcwd(current_dir,sizeof(current_dir)) != NULL){ cwd_p = opendir(current_dir); print_dirents(cwd_p); closedir(cwd_p); } else { perror("NULL pointer returned from getcwd()"); } return 0; } 它是这样工作的: $ gcc lsi.c && ./a.out filename.txt,1094297 a.out,1054235 ..,1068492 .,1122721 lsi.c,1094294 Volker Siegel 2018-09-10T21:19:42+08:002018-09-10T21:19:42+08:00 stat ./* 或者 man stat; stat --format=*f* ./*
ls
有-i
标志:但是,如果您喜欢冒险,请建立
ls -i
自己:它是这样工作的:
或者