0

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

karruma
  • 768
  • 1
  • 12
  • 32
  • probably the find's exec command is not correct? have a try with `-exec file {} +` just before the pipe (remove the semcolon too). – Marc Bredt Mar 05 '15 at 00:02

2 Answers2

2

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).

Joseph Larson
  • 8,530
  • 1
  • 19
  • 36
2

You can use rsync to copy one directory into another. If you need only some particular files, feel free to use --exclude and --include option.

rsync -avz --include='[iI]mage' --include='EPS' --exclude='*' source/ output/

To test command add rsync --dry-run option:

--dry-run perform a trial run with no changes made

You can find some examples of rsync include parameters in this thread.

Community
  • 1
  • 1
idobr
  • 1,537
  • 4
  • 15
  • 31
  • It will also work perfect with sudo command. Your initial version can have problems with it. Thanks to @joseph-larson for the note. – idobr Mar 05 '15 at 00:41
  • Thanks, Will --include examine if that file is an image? I would like to find and copy the files based on their mime-types (all images or possibly videos as well) and not on their extension. – karruma Mar 05 '15 at 12:12
  • ASFAIK, no. There is no such option. I'm sorry. I missed `file` in pipe of your command. There might be a workaround. I will check it later. – idobr Mar 05 '15 at 14:33