Reputation: 27
Using terminal on a mac, I have this bash command from my previous research that works great.
It searches only one level of a directory and moves all files (matching a text list of filenames) depositing them into a new directory.
while read filename; do mv DIR/${filename}.jpg NEWDIR/; done < filenamelist.txt
I now need it to able to search through any subfolders within DIR as well. The subfolders will all have random names usually. I don't think the MV move command has any recursive option, and haven't been able to find any other specific solutions. Should I be using a proper shell script instead of just one command line?
I'm still learning, would really appreciate any pointers! Thanks for reading.
Upvotes: 1
Views: 525
Reputation: 1631
You can use find
to search in subfolders:
while read filename; do find DIR/ -name "${filename}.jpg" -exec mv "{}" NEWDIR/ \; ; done < filenamelist.txt
You can use the mv
options -f
to force overwrite or -n
to not overwrite existing files.
Upvotes: 1