如何获取当前工作目录中的项目列表及其 inode 编号?
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
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句