Pay attention to your spaces and capital letters
What you want is something more like
find "$1" -name "*.$2" -exec stat -c "% N % u% U" {} \;
I have not tried this to find out if it does what you want, or to find out if the call to
stat
is right, but note the lack of spaces and that the hash-bang (
#!
) is followed by
/bin/bash
not
/ Bin / bash
Your solution does have one possible improvement I might recommend. Using
-exec
means that a new process is spawned for every file found by
find
. If you have thousands of matches, then this could take a very long time. A better solution might be to use
xargs
e.g.
find "$1" -name "*.$2" | xargs stat -c "% N % u% U"
See
man xargs for details
I'm also not sure about your second arg to
find
. I think what you have matches only on the file extension (e.g.
foo.txt). If you want to pass in a file glob to match, say
"*a*.bin", to find bar.bin, max.bin apple.bin, etc, then you could probably just use
"$2"
as the argument to
-name