Hi All,
I am trying to execute a find
command to retrieve all files of a specific type, e.g. images. Rather than using an OR'd list of suffixes with ~every~ image type, I wrote a small script that returns the mime-type (image, application, executable, etc). The problem is getting it into the find
command. The command: find ./ -type f -exec test $( ftype {} ) = 'image' \;
throws an error. The message from my "ftype" script is that it can't find the file named "{}". I know the "ftype" script works if used alone.
Here's the "ftype" script:
#!/usr/bin/bash
# SYNTAX: ftype [option] filename
# ... do argument handling ...
if [ ! -f "$filename" ]; then
echo -e "\nERR: File '$filename' not found\n" 1>&2
exit 1
fi
t=$( file --mime-type "$filename" )
t1=${t#*: }
echo "${t1%/*}"
I've never tried using the find command this way, so I don't know if the problem is something in the "ftype" script, or if I'm doing the find command incorrectly. And I'm trying to avoid using a for loop followed by an if statement. Can anyone help me out here?
Thanks,
Mitch
P.S. This is not homework - at my job I frequently have to search thru a lot of files for keywords, and searching only applicable files (or filtering out non-applicable files) would help make the search faster.