Move files to new folderif string matches
I'm trying to go through a number of folders and check their contents. If one or more of the files inside matches any of the strings in a given list, I would like to move those files to a new folder. I already have the new folder.
#!/bin/bash
find /path/to/sourcedir -type f | grep "string1\|string2\|string3" | while read f
do
mv "$f" /path/to/destination
done
If you have many strings you can skip "string1\|string2\|string3"
and
use grep --file=file_of_patterns.txt
where file_of_patterns.txt
is a textfile containing the strings you want to match (one per line)