我正在尝试找到一种方法来删除特定路径中超过 30 天的所有文件和目录。但在该路径中有一个我不想删除或修改的特定目录。我一直在阅读 -prune 但似乎无法让它发挥作用。到目前为止我尝试过的命令是:find "<path to directory" -prune -o -name "<name of excluded directory" -type f -mtime +30 -exec rm {} +
您的命令逻辑似乎find
混乱了。如果您想排除名为 的目录excludeme
并以其他方式打印文件名,您可以编写:
find /path/to/top/directory -name excludeme -prune -o -type f -print
Run Code Online (Sandbox Code Playgroud)
回想一下,这-o
是一个逻辑OR
,因此任何有效的条件都-prune
需要与-o
命令位于同一侧-prune
。
考虑到这一点,我们最终得到:
find "<path to directory" \
-name "<name of excluded directory> -prune -o \
-type f -mtime +30 -exec rm {} +
Run Code Online (Sandbox Code Playgroud)