This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Delete all files with a pattern.

I have thousands of txt files in one folder. Many of them are unnecessary for me. I want to delete all unnecessary files at once. If I do this manually (by opening every file, see it's content and delete it) it will require a lot of time and efforts. But I have some patterns (some words) (words are the content of the file, not the name of the file) that unnecessary files have. My required files do not have these patterns. So unnecessary files can be filtered and deleted using these patterns.

I have attached 2 screenshots of unnecessary files for better understanding. Highlighted word can be used as pattern. Highlighted word can be used as pattern... Highlighted word can be used as pattern...

file pattern delete

Hello Saroha!

We believe that this post does not fit the main topic of this site.

Not a bioinformatics question

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.

Cheers!

for loop, 
     check pattern using grep, 
     check the $?, 0 means found,
     then you can delete it.

Hint: find and the -exec flag.

0 answers

No answers yet.

Log in to answer this question.