在 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
命令)。