20c9 What does "-f" option do for "find" on FreeBSD? [Archive] - The FreeBSD Forums

PDA

View Full Version : What does "-f" option do for "find" on FreeBSD?


YZMSQ
April 8th, 2011, 15:34
Hello, there:
I'm now learning command line from scratch on FreeBSD, and now there's a problem relating to "find" confusing me. In "find" manual, it introduces the "-f" option with following description:

-f Specify a file hierarchy for find to traverse. File hierarchies
may also be specified as the operands immediately following the
options.

However, there's no further guide and example for that. I tried it myself with these output:

justin@zust.pts/0 ~ % ls test/mydoc/myfile/
myfile mytime myway
justin@zust.pts/0 ~ % find test/mydoc/myfile/ -type f -iname "*way*"
test/mydoc/myfile/myway
justin@zust.pts/0 ~ % find -f ~/test/mydoc/myfile -type f -iname "*way*"
find: illegal option -- t
find: illegal option -- y
find: illegal option -- p
find: illegal option -- e
/home/justin/test/mydoc/myfile/myway
find: f: No such file or directory
justin@zust.pts/0 ~ % find -f ~/test/ mydoc/myfile -type f -iname "*way*"
/home/justin/test/mydoc/myfile/myway
find: mydoc/myfile: No such file or directory
justin@zust.pts/0 ~ % find -f ~ /test/mydoc/myfile -type f -iname "*way*"
/home/justin/Art/music/Secret Garden/Always There.mp3
/home/justin/Download/11.A Thousand Miles Away.mp3
/home/justin/Download/12.Gifts Along The Way.mp3
/home/justin/Download/14.Always Near.mp3
/home/justin/Personal_University/其它/The_Open_Source_Way.pdf
/home/justin/.goldendict/WyabdcRealPeopleTTS/a/always.wav
/home/justin/.goldendict/WyabdcRealPeopleTTS/a/anyway.wav
/home/justin/.goldendict/WyabdcRealPeopleTTS/a/away.wav
/home/justin/.goldendict/WyabdcRealPeopleTTS/b/breezeway.wav
/home/justin/.goldendict/WyabdcRealPeopleTTS/d/doorway.wav
/home/justin/.goldendict/WyabdcRealPeopleTTS/f/freeway.wav
/home/justin/.goldendict/WyabdcRealPeopleTTS/g/gangway.wav
/home/justin/.goldendict/WyabdcRealPeopleTTS/g/gateway.wav
/home/justin/.goldendict/WyabdcRealPeopleTTS/h/hallway.wav
/home/justin/.goldendict/WyabdcRealPeopleTTS/h/headway.wav
/home/justin/.goldendict/WyabdcRealPeopleTTS/h/highway.wav
/home/justin/.goldendict/WyabdcRealPeopleTTS/l/leeway.wav
/home/justin/.goldendict/WyabdcRealPeopleTTS/m/motorway.wav
/home/justin/.goldendict/WyabdcRealPeopleTTS/r/railway.wav
/home/justin/.goldendict/WyabdcRealPeopleTTS/r/roadway.wav
/home/justin/.goldendict/WyabdcRealPeopleTTS/s/sideways.wav
/home/justin/.goldendict/WyabdcRealPeopleTTS/s/slantways.wav
/home/justin/.goldendict/WyabdcRealPeopleTTS/s/stairway.wav
/home/justin/.goldendict/WyabdcRealPeopleTTS/s/stowaway.wav
/home/justin/.goldendict/WyabdcRealPeopleTTS/s/subway.wav
/home/justin/.goldendict/WyabdcRealPeopleTTS/s/sway.wav
/home/justin/.goldendict/WyabdcRealPeopleTTS/w/way.wav
/home/justin/.goldendict/WyabdcRealPeopleTTS/w/waylaid.wav
/home/justin/.goldendict/WyabdcRealPeopleTTS/w/waylay.wav
/home/justin/.goldendict/WyabdcRealPeopleTTS/w/wayward.wav
/home/justin/.lyrics/Always There.lrc
/home/justin/.icons/Macbuntu-Icons/status/24/user-away.png
/home/justin/.icons/Macbuntu-Icons/status/24/user-away-panel.png
/home/justin/.icons/Macbuntu-Icons/status/24/empathy-away.png
/home/justin/.icons/Macbuntu-Icons/status/24/empathy-extended-away.png
/home/justin/.icons/Macbuntu-Icons/status/22/user-away.png
/home/justin/.icons/Macbuntu-Icons/status/22/user-away-panel.png
/home/justin/.icons/Macbuntu-Icons/status/22/empathy-away.png
/home/justin/.icons/Macbuntu-Icons/status/22/empathy-extended-away.png
/home/justin/.icons/Macbuntu-Icons/status/16/user-away.png
/home/justin/.icons/Macbuntu-Icons/status/16/user-away-panel.png
/home/justin/.icons/Macbuntu-Icons/status/16/empathy-away.png
/home/justin/.icons/Macbuntu-Icons/status/16/empathy-extended-away.png
/home/justin/.icons/Macbuntu-Icons/apps/scalable/kopete_some_away.png
/home/justin/.icons/Macbuntu-Icons/apps/scalable/kopete_all_away.png
/home/justin/test/mydoc/myfile/myway
find: /test/mydoc/myfile: No such file or directory

So, could you help me, please? Thank you in advance. :P

wblock@
April 8th, 2011, 16:45
Verified. Option parsing bug, I'd say. A quick check didn't find this in the PR database, but it might not be in find itself.


% find -f /usr/ports -name Makefile -exec grep -H REINPLACE {} \+ | less
find: illegal option -- n
find: illegal option -- a
find: illegal option -- m
find: illegal option -- e
/usr/ports/lang/otcl/Makefile: @${REINPLACE_CMD} -e 's|/usr/X11R6|${LOCALBASE}|g' \
/usr/ports/lang/otcl/Makefile: @${REINPLACE_CMD} -e 's|../lib/tcl$$TCL_HI_VERS|${TCL_LIBDIR}|g' \
/usr/ports/lang/otcl/Makefile: @${REINPLACE_CMD} -e 's|../lib/tk$$TK_HI_VERS|${TK_LIBDIR}|g' \


Please enter a PR (http://www.freebsd.org/support/bugreports.html).

jilles@
April 15th, 2011, 13:15
It is strange that find does not abort when it sees an invalid option, but I think your command is incorrect anyway.

The things like "-print" are operands, not options and therefore some sort of separation is required so that they are not seen as options. This can be the "--" end of options marker, a non-"-f" pathname or an "!" or "(" operand.

If you do not want to use "-f" because it is not portable, prepend "./" to any pathnames that start with "-" or are "!" or "(". Note that this prepending is reflected in the output.

wblock@
April 15th, 2011, 16:48
The synopsis in find doesn't show a --, and the examples don't use -f at all. Maybe this is a regression that few have noticed since the -f is rarely used.

0