too*_*kit 21
怎么样:
grep -L foo *.txt | xargs rm
grep -L bar *.txt | xargs rm
Run Code Online (Sandbox Code Playgroud)
如果文件确实不包含foo,则第一行会删除它.
如果文件确实不包含bar,则第二线将其删除.
同时包含只有文件foo和bar应留
-L, --files-without-match
Suppress normal output; instead print the name of each input
file from which no output would normally have been printed. The
scanning will stop on the first match.
Run Code Online (Sandbox Code Playgroud)
另见@Mykola Golubyev的帖子放置循环.
Myk*_*yev 11
list=`Word1 Word2 Word3 Word4 Word5`
for word in $list
grep -L $word *.txt | xargs rm
done
Run Code Online (Sandbox Code Playgroud)
除上述答案外:使用换行符作为分隔符来处理带空格的文件名!
grep -L $word $file | xargs -d '\n' rm
Run Code Online (Sandbox Code Playgroud)