Amy Amy - 10 months ago 18
Bash Question

Find files with certain strings in names (from a large list)

I'm pretty new to scripting, and I'm using Cygwin to try and find file names that contain strings from a large list. I need to get an output list of the filenames or just move them all to a central directory (either is fine). It has to be able to check several directory levels (probably maxdepth 3). I've been doing this:

find ./incoming -type d \( -name "*012345*" -o -name "*678910*" -o -name "*111213*" \) > moved.txt

...except it's not ideal because the lists I'm working with can contain thousands of strings. I've also tried this:

xargs -a files_to_move.txt mv -t ./moved

...except since I don't know the whole names for the files, it's unsuccessful. Any ideas?


Assuming all strings are in list.txt

for i in $(cat list.txt); do find <your_dir> -name "*${i}*" ; done