Inside a directory, how can I delete files that lack any of the words specified, so that only files that contain ALL the words are left? I tried to write a simple bash shell script using grep and rm commands, but I got lost. I am totally new to Linux, any help would be appreciated
Share
How about:
If a file does not contain
foo, then the first line will remove it.If a file does not contain
bar, then the second line will remove it.Only files containing both
fooandbarshould be leftSee also @Mykola Golubyev’s post for placing in a loop.