在 CentOS 系统中,你可以使用 find
命令来过滤特定文件类型。readdir
是一个库函数,用于读取目录内容,而不是一个命令行工具。下面是如何使用 find
命令来过滤特定文件类型的示例:
.txt
文件:find /path/to/directory -type f -name "*.txt"
这里,/path/to/directory
是你要搜索的目录,-type f
表示只查找文件,-name "*.txt"
表示查找扩展名为 .txt
的文件。
.txt
和 .md
文件:find /path/to/directory -type f \( -name "*.txt" -o -name "*.md" \)
这里,-o
表示逻辑或(OR),\(
和 \)
用于对条件进行分组。
find /path/to/directory -type d
.txt
文件,但排除名为 temp
的目录:find /path/to/directory -type d -name "temp" -prune -o -type f -name "*.txt" -print
这里,-prune
选项表示排除名为 temp
的目录,-print
表示打印满足条件的文件路径。
你可以根据需要修改 /path/to/directory
、文件类型和扩展名来适应你的需求。