Welcome to the Linux Foundation Forum!

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

Options
eldaria
eldaria Posts: 1
edited October 2016 in Command Line/Scripting

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?

 

Comments

  • paolo91
    Options

    The problem I think it is the - after the cp command.

    In which directory do you need to find these files?

Categories

Upcoming Training