8

I have a large directory full of various shapefiles. I'd like to move or copy all of the files ending in _31. or _32. to a different directory (mac osx).

## Find all shapefiles ending in 31
find ./ -iname '*_31.*' 2>/dev/null

## Find all shapefiles ending in 32
find ./ -iname '*_32.*' 2>/dev/null

The above find calls successfully find all of the desired files. Now I'd like to move or copy those results to the new directory. Any ideas?

1
  • 1
    I used find ./ -iname '_32.' | xargs -I '{}' mv {} ../.. and it worked perfect, thanks! Commented Mar 10, 2020 at 0:53

1 Answer 1

9

This is a job for xargs!

find ./ -iname '*_32.*' | xargs -I _ cp _ destination

xargs will take the output of find and run a command on each line.

-I _ sets a place holder for the incoming line that is then used in the cp command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.