在 Ubuntu(Linux)里,opendir 不是一条命令,而是一个 C 语言标准库函数,定义在 <dirent.h> 头文件中,用于打开一个目录。
#include <dirent.h>
DIR *opendir(const char *name);
头文件位置
/usr/include/dirent.h
实际实现通常在:
/usr/include/x86_64-linux-gnu/bits/dirent.h
库文件
opendir 由 glibc 提供,链接时一般不需要额外参数(默认链接 libc)。
readdir:读取目录项closedir:关闭目录rewinddir:重置目录流#include <stdio.h>
#include <dirent.h>
int main() {
DIR *dir = opendir(".");
struct dirent *entry;
while ((entry = readdir(dir)) != NULL) {
printf("%s\n", entry->d_name);
}
closedir(dir);
return 0;
}
编译:
gcc test.c -o test
你可能想用的是:
ls(列出目录)find(查找文件)tree(目录树)如果你是因为 报错 opendir not found 或 man 查不到,可以把具体错误信息发出来,我可以帮你精准定位。