A message for Linux.com registered users: We are in the process of making changes to the Linux forums. Starting Monday, 8/13/18 at 6:00 PM PT, you will be unable to access the forums. They will re-launch as soon as possible on Wednesday, 8/15/18 with new features and improved functionality. Thank you for your patience and stay tuned for the new improved forums.

October 19, 2016

Find files of certain file type using file, and copy them.

So I been trying to figure out if I can do a one liner to find all files of a certain type in a directory structure full of files with no extension, using file, and if they are a certain file type copy them to a folder.

So far I got this:

find -type f -exec file {}  \; | awk '/Ogg/ {print $1}' | sed s/://

This will generate a list of all the files, so I added another file statement just to see if it was working before activating a cp on it, but it seems i'm doing something wrong.

find -type f -exec file {}  \; | awk '/Ogg/ {print $1}' | sed s/:// | file -
/dev/stdin: ASCII text

Trying to do a copy on it does not work either.
find -type f -exec file {}  \; | awk '/Ogg/ {print $1}' | sed s/:// | cp - /tmp
cp: cannot stat ‘-’: No such file or directory
find: `file' terminated by signal 13
find: `file' terminated by signal 13
find: `file' terminated by signal 13
find: `file' terminated by signal 13
find: `file' terminated by signal 13
find: `file' terminated by signal 13
find: `file' terminated by signal 13

My guess is that I in some way need to convert the output to something but i'm not sure how to porceed?

 

Click Here!