Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find: -printf: unknown option [duplicate]

Possible Duplicate:
Why does Mac's $find not have the option -printf?

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

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

Basically, I am attemtping to find out in my public_html directory names of all directories that have *.php extension. and then print out the directory in which that file is found. The output of this is piped to sort, duplicate entries are removed by the -u flag, and the result is stored in new file dirlist.txt

But what I am getting upon execution is :

find: -printf: unknown option 

Not sure where I am getting this wrong

Thanks

like image 848
user1020069 Avatar asked Mar 20 '12 16:03

user1020069


2 Answers

Your version of find seems to have no -printf option.

I would do the same task like so:

find public_html -type f -name '*.php' | xargs -n1 dirname | sort -u > dirlist.txt
like image 82
bukzor Avatar answered Sep 25 '22 06:09

bukzor


yes, your version does not seem to have -printf option - Mac variant doesnt i know - there may be others

your alternative is to pipe it to sed and sort, like so:

find public_html -name '*.php'|sed 's#\(.*\)/.*#\1#' |sort -u 
like image 24
Vijay Agrawal Avatar answered Sep 24 '22 06:09

Vijay Agrawal