给定主路径 ./class
并且在 class
中是子目录 student1
,student2
, student3
...student100.
在这些子目录中还有其他子目录history
,geography
,Math
。这些子目录中的每一个都有数百个文件。我想保留所有在 Math
中具有字符串 pass
的文件,而不影响其他主题中的文件。到目前为止,我可以cd
到Math
并执行此操作:
找到 . -类型 f -print0 | xargs --null grep -Z -L '通过' | xargs --null rm
但是cd
到100个子目录
和rm
中的Math
是无效的 不需要的
文件。
一个 grep 如何只 Math
并执行上面的代码?
最佳答案
下面应该可以解决问题
for i in `find . -type d -name *Math* -exec find {} -type f -not -name *pass* \;`; do rm $i ; done
关于linux - 查找子目录并删除不包含特定字符串的文件 LINUX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48691119/