我正在尝试删除某些排除目录中的所有内容。我目前正在使用此:
find . -type f | grep -vZf ../../exclude.file | xargs rm -rf
该exclude.file
包含:
*log*
world*
crash-reports
banned-ips*
我不想删除world
,,log
或crash-reports
文件夹或其任何内容(*表示备份,其生成为world.zip
)。
上面的命令可以执行此操作,但是不会删除非空目录。例如,Config
目录已保留,但我需要将其删除。
我也尝试过类似以下内容:
find -maxdepth 0 -not -name '*log*' -not -name 'crash-reports' -not -name 'world*' | xargs rm -rf
但是我仍然得到相同的结果。
有没有办法做到这一点?
-type f
只会找到文件,而不是目录。-maxdepth 0
只会在(.
)中找到您要搜索的目录。您必须找到实际要传递给的文件rm
。
执行此操作的标准方法是排除目录及其所有内容,如下所示(未经测试!):
find . -mindepth 1 \( -name '*log*' -o -name 'crash-reports' -o -name 'world*' \) -prune -o -print
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句