Find: -printf: unknown parameter

Possible duplicate:
Why doesn't Mac $ find have the -printf option?

Not sure what happened with the following command, but can anyone spot the error:

find public_html -name '*.php'  -printf '%h \n' | sort -u > dirlist.txt

      

Basically, I'm trying to figure out in my public_html directories the names of all directories with the * .php extension. and then print the directory that this file is in. The result of this is sorted by channel, duplicate entries are removed using the -u flag, and the result is saved in a new dirlist.txt file

But what I get after execution is:

find: -printf: unknown option 

      

Don't know where i go wrong

thank

+3


source to share


2 answers


Your version of search doesn't have the -printf option.

I would accomplish the same task:



find public_html -type f -name '*.php' | xargs -n1 dirname | sort -u > dirlist.txt

      

+5


source


yes, your version doesn't seem to have the -printf option - Mac option don't know - there may be others

Your alternative is to pipe it to sed and sort it like:



find public_html -name '*.php'|sed 's#\(.*\)/.*#\1#' |sort -u 

      

+1


source







All Articles