You can pass a directory as a target to grep with -R and a file of input patterns with -f:
-f FILE, --file=FILE Obtain patterns from FILE, one per line. If this option is used multiple times or is combined with the -e (--regexp) option, search for all patterns given. The empty file contains zero patterns, and therefore matches nothing. -R, --dereference-recursive Read all files under each directory, recursively. Follow all symbolic links, unlike -r. So, you're looking for:
grep -Ff subset.txt -r objects/ You can get the list of matching files with:
grep -Flf subset.txt -r objects/ So, if your final list isn't too long, you can just do:
mv $(grep -Flf subset.txt -r objects/) new_dir/ If that returns an argument list too long error, use:
grep -Flf subset.txt -r objects/ | xargs -I{} mv {} bar/ And if your file names can contain spaces or other strange characters, use (assuming GNU grep):
grep -FzlfFZlf subset.txt -r objects/ | xargs -0I{} mv {} bar/ Finally, if you want to exclude binary files, use:
grep -IFZlf subset.txt -r objects/ | xargs -0I{} mv {} bar/