我想递归删除所有.pyc和.pyo文件,但要排除某个目录。我只是遇到了一些局限性,即忽略时find不能删除。我尝试将结果传递到,xargs rm
但是也失败了。
find . -not \( -path somedir -prune \) -name '*.py[co]' -exec rm '{}' \;
错误:
find: The -delete action atomatically turns on -depth, but -prune does nothing when -depth is in effect. If you want to carry on anyway, just explicitly use the -depth option.
这也会失败:
find . -type f -not -path 'somdir/*' -name '*.py[co]' -print0 | xargs -0 rm
版本:
因此,似乎我需要.
在目录前面显式放置前缀。我不确定我是否完全理解原因,但是对于这种情况下的其他任何人:
失败:
find . -type f -not -path 'somdir/*' -name '*.py[co]' -print0 | xargs -0 rm
作品:
find . -type f -not -path './somdir/*' -name '*.py[co]' -print0 | xargs -0 rm
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句