6

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

Community
  • 1
  • 1
user1020069
  • 1,540
  • 7
  • 24
  • 41

2 Answers2

10

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
bukzor
  • 37,539
  • 11
  • 77
  • 111
  • I guess this is because I am following a linux manual on a OS X terminal ! – user1020069 Mar 20 '12 at 17:06
  • thanks all! the stackoverflow community is amazing, hopefully I am getting up to speed to start contributing as well ! – user1020069 Mar 20 '12 at 17:13
  • @user1020069: I recommend updating your name. – bukzor Mar 20 '12 at 17:14
  • @bukzor Similarly, do you know how to do the following without the -printf option (which I don't have)? --> find . -printf "%p (%s, %Tb %Td %TY %TH:%TM)\n" Basically I want the size and date/time to be listed as well. – Jobs Mar 07 '19 at 23:34
1

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 
Vijay Agrawal
  • 3,751
  • 2
  • 23
  • 25