在Ubuntu中,你可以使用find命令来按文件类型筛选目录中的文件。readdir是一个C语言库函数,用于读取目录内容,但在这里我们关注的是如何在Ubuntu中使用命令行工具。
以下是一些示例,说明如何使用find命令按文件类型筛选:
find /path/to/directory -type f
find /path/to/directory -type d
find /path/to/directory -type l
find /path/to/directory -type f ! -type d ! -type l
.txt文件:find /path/to/directory -type f -name "*.txt"
.txt和.md文件:find /path/to/directory -type f \( -name "*.txt" -o -name "*.md" \)
请注意,/path/to/directory是你要搜索的目录的路径。根据需要替换为实际路径。