Search code examples
bashfindcpio

Find and copy all images preserving the folder structure


I am trying to find and copy all the images from one location to another preserving the folder structure. I have tried using the following command:

 sudo find . -type f -exec file {} \; | awk -F: '{ if ($2 ~/[Ii]mage|EPS/) print $1}'  | cpio -pdm  /media/newlocation

This works fine for couple of minutes (I have gigabytes of files to be found and copies) but after some time I am getting the following error:

find: `file' terminated by signal 13

What is wrong with the command? Is there better way of doing it?

Regards


Solution

  • I'm not sure why you'd get sigpipe.

    Rather than letting find do an exec, you could try:

    find . -type f -print | xargs file | awk ....

    That is -- just let find print them out and xargs file to run the file command.

    Note that your sudo command will do the find but it's not going to sudo the entire line. That's going to cause you more trouble (if you need sudo at all).