在 Linux 中,可以使用 find 命令来递归遍历目录。find 命令非常强大,可以根据文件名、大小、修改时间等条件搜索文件和目录。以下是一些常用的 find 命令示例:
find /path/to/directory 将 /path/to/directory 替换为要遍历的目录路径。
find /path/to/directory -type f 这将仅显示目录中的文件,不包括子目录。
find /path/to/directory -type d 这将仅显示目录中的子目录,不包括文件。
find /path/to/directory -type f -name "filename.ext" 将 filename.ext 替换为要查找的文件名。
find /path/to/directory -type f -name "*.txt" 这将查找所有扩展名为 .txt 的文件。
这些示例只是 find 命令功能的一部分。find 命令还有许多其他选项和功能,可以根据需要进行组合和定制。要了解更多关于 find 命令的信息,请查阅其手册页(通过运行 man find 命令)。