Re: find(1) manpage patch

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Joachim Schipper
Date: Tuesday, September 14, 2010 - 4:42 am

On Tue, Sep 14, 2010 at 04:35:24AM +0100, Stuart Henderson wrote:

I like those tweaks too; thanks Ingo!


That's a good point.


How about the following? (First diff is relative to Ingo's diff; second
diff is relative to HEAD.)

I'm not too happy about enumerating mistakes like this, but these *are*
both quite common, and I can't think of any other common mistakes.

		Joachim

--- find.1.ingo	Tue Sep 14 13:32:26 2010
+++ find.1.mine	Tue Sep 14 13:32:51 2010
@@ -383,9 +383,9 @@
 by a newline
 .Pq Ql \en
 character.
-This is dangerous in conjunction with
-.Xr xargs 1 ,
-see
+This is dangerous when used with other programs (like
+.Xr xargs 1
+or a shell), see
 .Sx CAVEATS .
 .It Ic -print0
 This primary always evaluates to true.
@@ -650,10 +650,11 @@
 Using
 .Nm
 in combination with
-.Xr xargs 1
-requires some care:
+other programs requires some care:
 .Pp
 .Dl "$ find . -name \e*.jpg | xargs rm"
+or
+.Dl "$ rm `find . -name \e*.jpg`"
 .Pp
 would, given a file named
 .Pa "important .jpg"


Index: find.1
===================================================================
RCS file: /cvs/src/usr.bin/find/find.1,v
retrieving revision 1.78
diff -u -p -r1.78 find.1
--- find.1	15 Jul 2010 20:51:38 -0000	1.78
+++ find.1	14 Sep 2010 11:32:14 -0000
@@ -383,10 +383,17 @@ It prints the pathname of the current fi
 by a newline
 .Pq Ql \en
 character.
+This is dangerous when used with other programs (like
+.Xr xargs 1
+or a shell), see
+.Sx CAVEATS .
 .It Ic -print0
 This primary always evaluates to true.
 It prints the pathname of the current file to standard output, followed
-by a null character.
+by a null character, suitable for use with the
+.Fl 0
+option to
+.Xr xargs 1 .
 .It Ic -prune
 This primary always evaluates to true.
 It causes
@@ -525,11 +532,13 @@ ending in a dot and single digit, but sk
 .Pp
 .Dl "$ find /usr/src -path /usr/src/gnu -prune -or -name \e*.[0-9]"
 .Pp
-Find and remove all *.jpg files in the current working directory:
+Find and remove all *.jpg and *.gif files under the current working
+directory
+.Pq see also Sx CAVEATS :
 .Pp
-.Dl "$ find . -name \e*.jpg -exec rm {} \e;"
+.Dl "$ find . \e( -name \e*.jpg -o -name \e*.gif \e) -exec rm {} \e;
 or
-.Dl "$ find . -name \e*.jpg | xargs rm"
+.Dl "$ find . \e( -name \e*.jpg -o -name \e*.gif \e) -print0 | xargs -0r rm"
 .Sh SEE ALSO
 .Xr chflags 1 ,
 .Xr chmod 1 ,
@@ -637,6 +646,25 @@ In particular, the characters
 and
 .Ql \&;
 may have to be escaped from the shell.
+.Pp
+Using
+.Nm
+in combination with
+other programs requires some care:
+.Pp
+.Dl "$ find . -name \e*.jpg | xargs rm"
+or
+.Dl "$ rm `find . -name \e*.jpg`"
+.Pp
+would, given a file named
+.Pa "important .jpg"
+(with a space character in the middle), remove
+.Pa important .
+Use the
+.Ic -print0
+or
+.Ic -exec
+primaries instead.
 .Pp
 As there is no delimiter separating options and file names or file
 names and the
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: find(1) manpage patch, Ingo Schwarze, (Mon Sep 13, 4:48 pm)
Re: find(1) manpage patch, Stuart Henderson, (Mon Sep 13, 8:35 pm)
Re: find(1) manpage patch, Jason McIntyre, (Mon Sep 13, 9:58 pm)
Re: find(1) manpage patch, Joachim Schipper, (Tue Sep 14, 4:42 am)