在 CentOS 系统中,你可以使用 find
命令来查找特定类型的文件。readdir
是一个库函数,用于读取目录内容,而不是一个命令行工具。下面是如何使用 find
命令查找特定文件类型的示例:
- 查找所有
.txt
文件:
find /path/to/directory -type f -name "*.txt"
这里,/path/to/directory
是你要搜索的目录,-type f
表示查找文件类型为普通文件,-name "*.txt"
表示查找以 .txt
结尾的文件。
- 查找所有
.jpg
文件:
find /path/to/directory -type f -name "*.jpg"
- 查找特定目录及其子目录下的所有
.py
文件:
find /path/to/directory -type f -name "*.py"
- 查找特定目录下的所有
.md
文件,但不包括子目录:
find /path/to/directory -maxdepth 1 -type f -name "*.md"
这里,-maxdepth 1
表示只在指定目录下搜索,而不进入子目录。
你可以根据需要修改 /path/to/directory
和文件类型(例如 *.jpg
、*.py
等)。如果你需要在其他目录中搜索,只需将 /path/to/directory
替换为目标目录即可。