K.Mandla's blog of Linux experiences

Skimming subfolders for files to copy

Basic tip today, this time for sifting through a directory tree and plucking out files that match a certain filter.

I needed to move some of the office photo collection off CD and USB into a different location to sort them manually. A lot of international characters and intermingled, unwanted files were complicating things.

I’m sure there are lots of ways to do this, but this is what I did.

find /media/ -iname "*jpg" -exec cp '{}' /home/kmandla/hold/ \;

Obviously you can change that to move the files, or anything else you like.

The regular cp command — or as I was trying to use it, cp -Rv /media/*jpg /home/kmandla/hold — wasn’t working with me, and my variations on that line were likewise failures.

find did the job right the first time. And was quicker than pointing and clicking, that’s for sure.