gpt4 book ai didi

linux - 查找子目录并删除不包含特定字符串的文件 LINUX

转载 作者:太空宇宙 更新时间:2023-11-04 12:11:37 25 4
gpt4 key购买 nike

给定主路径 ./class 并且在 class 中是子目录 student1,student2, student3...student100. 在这些子目录中还有其他子目录history,geography,Math。这些子目录中的每一个都有数百个文件。我想保留所有在 Math 中具有字符串 pass 的文件,而不影响其他主题中的文件。到目前为止,我可以cdMath 并执行此操作:

找到 . -类型 f -print0 | xargs --null grep -Z -L '通过' | xargs --null rm

但是cd100个子目录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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com