在 Linux 下,可以使用 find
命令来实现目录遍历。find
命令可以在指定目录下搜索文件和子目录,并根据条件进行过滤。以下是一些常用的 find
命令示例:
find /path/to/directory
find /path/to/directory -type f
find /path/to/directory -type d
find /path/to/directory -name "filename.ext"
find /path/to/directory -type f -exec file {} \; | grep "text"
find /path/to/directory -type f -size +1M # 查找大于 1MB 的文件
find /path/to/directory -type f -mtime -7 # 查找最近 7 天内修改过的文件
这些示例只是 find
命令功能的一部分。你可以根据需要组合不同的选项和条件来实现更复杂的目录遍历。要了解更多关于 find
命令的信息,请查阅 Linux 手册页(通过运行 man find
命令)。