Re: xargs PF or BPF

2006-02-14 Thread Michael Schmidt

Matthias Kilian wrote:


And watch out for silly file names containing whitespace.

BTW: if this is a contest on creative use of find(1) and other
standard tools:

$ find . -type f | sed '[EMAIL PROTECTED]@grep -l -- foo @' | sh

Yes, this isn't robust against whitespace, either PLUS it's
inefficient. But in some cases the find ... | sed ... | sh pattern
is quite useful.
 



Sometime ago I have had the same problem with spaces in filenames and 
dealing with them as xargs parameters. There I have used (here only as 
an example):


find . -print | grep -i ' ' | xargs -I {} ls -ald {}

FYI, that has been on a non-OpenBSD system.
I4m not at my OpenBSD system at the moment, so I can4t check whether 
OpenBSD xargs supports the shown options. Maybe someone may test it.


One may check this at a directory with space-containing filenames.
Without the -I {} and {} parts you get funny output.

Have a nice day
Michael


--
Michael Schmidt MIRRORS:
DJGPP   ftp://ftp.fh-koblenz.de/pub/DJGPP/
Ghostscript ftp://ftp.fh-koblenz.de/pub/Ghostscript/



Re: xargs PF or BPF

2006-02-14 Thread Otto Moerbeek
On Tue, 14 Feb 2006, Michael Schmidt wrote:

 Matthias Kilian wrote:
 
  And watch out for silly file names containing whitespace.
  
  BTW: if this is a contest on creative use of find(1) and other
  standard tools:
  
  $ find . -type f | sed '[EMAIL PROTECTED]@grep -l -- foo @' | sh
  
  Yes, this isn't robust against whitespace, either PLUS it's
  inefficient. But in some cases the find ... | sed ... | sh pattern
  is quite useful.
   
 
 Sometime ago I have had the same problem with spaces in filenames and dealing
 with them as xargs parameters. There I have used (here only as an example):
 
 find . -print | grep -i ' ' | xargs -I {} ls -ald {}
 
 FYI, that has been on a non-OpenBSD system.
 I4m not at my OpenBSD system at the moment, so I can4t check whether OpenBSD
 xargs supports the shown options. Maybe someone may test it.
 
 One may check this at a directory with space-containing filenames.
 Without the -I {} and {} parts you get funny output.
 

Well, -print0 in find and xargs -0 are designed to deal with that.
Sadly these are not in POSIX (which is not documented correctly in the
xargs case).

-Otto



Re: xargs PF or BPF

2006-02-14 Thread Ray Lai
On Tue, Feb 14, 2006 at 11:39:45AM +0100, Otto Moerbeek wrote:
 On Tue, 14 Feb 2006, Michael Schmidt wrote:
 
  Matthias Kilian wrote:
  
   And watch out for silly file names containing whitespace.
   
   BTW: if this is a contest on creative use of find(1) and other
   standard tools:
   
   $ find . -type f | sed '[EMAIL PROTECTED]@grep -l -- foo @' | sh
   
   Yes, this isn't robust against whitespace, either PLUS it's
   inefficient. But in some cases the find ... | sed ... | sh pattern
   is quite useful.

  
  Sometime ago I have had the same problem with spaces in filenames and 
  dealing
  with them as xargs parameters. There I have used (here only as an example):
  
  find . -print | grep -i ' ' | xargs -I {} ls -ald {}
  
  FYI, that has been on a non-OpenBSD system.
  I4m not at my OpenBSD system at the moment, so I can4t check whether OpenBSD
  xargs supports the shown options. Maybe someone may test it.
  
  One may check this at a directory with space-containing filenames.
  Without the -I {} and {} parts you get funny output.
  
 
 Well, -print0 in find and xargs -0 are designed to deal with that.
 Sadly these are not in POSIX (which is not documented correctly in the
 xargs case).

Does this diff fix it?  (I also added a comma after the last -R.)

-Ray-

Index: xargs.1
===
RCS file: /cvs/src/usr.bin/xargs/xargs.1,v
retrieving revision 1.15
diff -u -r1.15 xargs.1
--- xargs.1 12 Sep 2005 09:44:59 -  1.15
+++ xargs.1 14 Feb 2006 13:37:48 -
@@ -316,7 +316,8 @@
 .St -p1003.2
 compliant.
 The
-.Fl J , o , P , R
+.Fl 0 , J , o , P ,
+.Fl R ,
 and
 .Fl r
 options are non-standard



Re: xargs PF or BPF

2006-02-14 Thread Otto Moerbeek
On Tue, 14 Feb 2006, Ray Lai wrote:

 On Tue, Feb 14, 2006 at 11:39:45AM +0100, Otto Moerbeek wrote:
  On Tue, 14 Feb 2006, Michael Schmidt wrote:
  
   Matthias Kilian wrote:
   
And watch out for silly file names containing whitespace.

BTW: if this is a contest on creative use of find(1) and other
standard tools:

$ find . -type f | sed '[EMAIL PROTECTED]@grep -l -- foo @' | sh

Yes, this isn't robust against whitespace, either PLUS it's
inefficient. But in some cases the find ... | sed ... | sh pattern
is quite useful.
 
   
   Sometime ago I have had the same problem with spaces in filenames and 
   dealing
   with them as xargs parameters. There I have used (here only as an 
   example):
   
   find . -print | grep -i ' ' | xargs -I {} ls -ald {}
   
   FYI, that has been on a non-OpenBSD system.
   I4m not at my OpenBSD system at the moment, so I can4t check whether 
   OpenBSD
   xargs supports the shown options. Maybe someone may test it.
   
   One may check this at a directory with space-containing filenames.
   Without the -I {} and {} parts you get funny output.
   
  
  Well, -print0 in find and xargs -0 are designed to deal with that.
  Sadly these are not in POSIX (which is not documented correctly in the
  xargs case).
 
 Does this diff fix it?  (I also added a comma after the last -R.)

I already committed a similar diff,

-Otto

 
 -Ray-
 
 Index: xargs.1
 ===
 RCS file: /cvs/src/usr.bin/xargs/xargs.1,v
 retrieving revision 1.15
 diff -u -r1.15 xargs.1
 --- xargs.1   12 Sep 2005 09:44:59 -  1.15
 +++ xargs.1   14 Feb 2006 13:37:48 -
 @@ -316,7 +316,8 @@
  .St -p1003.2
  compliant.
  The
 -.Fl J , o , P , R
 +.Fl 0 , J , o , P ,
 +.Fl R ,
  and
  .Fl r
  options are non-standard



Re: xargs PF or BPF

2006-02-13 Thread Tim Donahue
On Monday 13 February 2006 17:13, Stuart Henderson wrote:
 On 2006/02/13 16:53, Jason Crawford wrote:
  On 2/13/06, Matthias Kilian [EMAIL PROTECTED] wrote:
   On Mon, Feb 13, 2006 at 02:03:27PM -0700, Diana Eichert wrote:
find /usr/src -name *.[c|h] -exec grep 'bpf.h' /dev/null {} \;

 it's in quotes, this is handled by find, not the shell.

   (b) pipeing to xargs(1) may be faster.
 
  why?


As done by find -exec, correct?
 grep foo 1 2 3 4 5 6 7 ...

 vs.


As done by xargs?
 grep foo 1
 grep foo 2
 grep foo 3
 ...

Wouldn't for a small list -exec be faster as it is a single invocation of the 
grep vs multiple invocations of grep for xargs.  

IIRC, the reason xargs exists is to get around limits posed by the number of 
args an application like rm or grep can take when passed a large list of 
arguments like, say, a recursive find for old files in your spam 
quarantine :-).  

Tim Donahue



Re: xargs PF or BPF

2006-02-13 Thread Martin Schröder
On 2006-02-13 18:10:53 -0500, Tim Donahue wrote:
 As done by xargs?
  grep foo 1
  grep foo 2
  grep foo 3

quote src=xargs(1)
 Any arguments specified on the command line are given to the utility upon
 each invocation, followed by some number of the arguments read from stan-
 dard input.  The utility is repeatedly executed until standard input is
 exhausted.
/quote

 Wouldn't for a small list -exec be faster as it is a single invocation of the 
 grep vs multiple invocations of grep for xargs.  

There won't be more invocations than necessary.

 IIRC, the reason xargs exists is to get around limits posed by the number of 
 args an application like rm or grep can take when passed a large list of 
 arguments like, say, a recursive find for old files in your spam 
 quarantine :-).  

That is _one_ reason.

Best
Martin
-- 
http://www.tm.oneiros.de



Re: xargs PF or BPF

2006-02-13 Thread Damien Miller
On Tue, 14 Feb 2006, noob lenoobie wrote:

 On Mon, 13 Feb 2006, Matthias Kilian wrote:
 (b) pipeing to xargs(1) may be faster.
 
 Why so many people is using xargs ?
 
 I mean for instance why bother use xargs AND a pipe to do somthing like this
 :
 
 find ./ -type f -print | xargs -i rm -f
 Instead of
 rm -f $(find ./ -type f -print)

Because that will fail when there are too many arguments, and will 
probably break on filenames with spaces (use xargs -0 for these).

-d



Re: xargs PF or BPF

2006-02-13 Thread Andrew Pinski

On Feb 13, 2006, at 9:24 PM, Damien Miller wrote:

Because that will fail when there are too many arguments, and will
probably break on filenames with spaces (use xargs -0 for these).


Why not use -exec in find?

find . -type f -name ttt -exec rm {}\;

-- Pinski



Re: xargs PF or BPF

2006-02-13 Thread Ted Unangst
On 2/13/06, Damien Miller [EMAIL PROTECTED] wrote:
  Why so many people is using xargs ?
 
  I mean for instance why bother use xargs AND a pipe to do somthing like this
  :
 
  find ./ -type f -print | xargs -i rm -f
  Instead of
  rm -f $(find ./ -type f -print)

 Because that will fail when there are too many arguments, and will
 probably break on filenames with spaces (use xargs -0 for these).

with either version, hilarity is sure to ensue when you discover an
accidentally created -r file.  always use --.



Re: xargs PF or BPF

2006-02-13 Thread Andrew Pinski

On Feb 13, 2006, at 9:53 PM, Jason Crawford wrote:


On 2/13/06, Andrew Pinski [EMAIL PROTECTED] wrote:

On Feb 13, 2006, at 9:24 PM, Damien Miller wrote:

Because that will fail when there are too many arguments, and will
probably break on filenames with spaces (use xargs -0 for these).


Why not use -exec in find?

find . -type f -name ttt -exec rm {}\;


Because as stated many times on this list already (originally to
correct me), that will execute rm for each file, while piping to xargs
will only run rm once xargs stops getting input, or when it hits max
command line length, in which case it will execute another rm based on
input from the pipe.


Time to write your own program in C instead if the time to invoke
rm is taking too much time.

-- Pinski



Re: xargs PF or BPF

2006-02-13 Thread Jason Crawford
On 2/13/06, Andrew Pinski [EMAIL PROTECTED] wrote:
 On Feb 13, 2006, at 9:24 PM, Damien Miller wrote:
  Because that will fail when there are too many arguments, and will
  probably break on filenames with spaces (use xargs -0 for these).

 Why not use -exec in find?

 find . -type f -name ttt -exec rm {}\;

Because as stated many times on this list already (originally to
correct me), that will execute rm for each file, while piping to xargs
will only run rm once xargs stops getting input, or when it hits max
command line length, in which case it will execute another rm based on
input from the pipe.

Jason



Re: xargs PF or BPF

2006-02-13 Thread Jason Crawford
On 2/13/06, Andrew Pinski [EMAIL PROTECTED] wrote:

 On Feb 13, 2006, at 9:53 PM, Jason Crawford wrote:

  On 2/13/06, Andrew Pinski [EMAIL PROTECTED] wrote:
  On Feb 13, 2006, at 9:24 PM, Damien Miller wrote:
  Because that will fail when there are too many arguments, and will
  probably break on filenames with spaces (use xargs -0 for these).
 
  Why not use -exec in find?
 
  find . -type f -name ttt -exec rm {}\;
 
  Because as stated many times on this list already (originally to
  correct me), that will execute rm for each file, while piping to xargs
  will only run rm once xargs stops getting input, or when it hits max
  command line length, in which case it will execute another rm based on
  input from the pipe.

 Time to write your own program in C instead if the time to invoke
 rm is taking too much time.

No point, xargs does what I need it to do, and is much more efficient
than having find execute rm itself. The fewer times you call execve(2)
the better.

Jason



Re: xargs PF or BPF

2006-02-13 Thread Damien Miller
On Mon, 13 Feb 2006, Andrew Pinski wrote:

 
 On Feb 13, 2006, at 9:24 PM, Damien Miller wrote:
  Because that will fail when there are too many arguments, and will
  probably break on filenames with spaces (use xargs -0 for these).
 
 Why not use -exec in find?
 
 find . -type f -name ttt -exec rm {}\;

this conversation is going in circles. Look back a couple of messages
in this very thread



Re: xargs PF or BPF

2006-02-13 Thread Andrew Pinski

On Feb 13, 2006, at 10:00 PM, Jason Crawford wrote:


Time to write your own program in C instead if the time to invoke
rm is taking too much time.


No point, xargs does what I need it to do, and is much more efficient
than having find execute rm itself. The fewer times you call execve(2)
the better.



One execve is enough? Then rewriting the script into C will save
all execve.  Do you think rm(1) does anything special,
other than remove(3)?

-- Pinski



Re: xargs PF or BPF

2006-02-13 Thread Damien Miller
On Mon, 13 Feb 2006, Andrew Pinski wrote:

 Time to write your own program in C instead if the time to invoke
 rm is taking too much time.

rm *is* a small program written in C. You need to consider how the 
tools actually invoke it - think about it for a while.

-d



Re: xargs PF or BPF

2006-02-13 Thread Matthias Kilian
On Mon, Feb 13, 2006 at 06:32:53PM -0800, Ted Unangst wrote:
   find ./ -type f -print | xargs -i rm -f
   Instead of
   rm -f $(find ./ -type f -print)
 
  Because that will fail when there are too many arguments, and will
  probably break on filenames with spaces (use xargs -0 for these).
 
 with either version, hilarity is sure to ensue when you discover an
 accidentally created -r file.  always use --.

And watch out for silly file names containing whitespace.

BTW: if this is a contest on creative use of find(1) and other
standard tools:

$ find . -type f | sed '[EMAIL PROTECTED]@grep -l -- foo @' | sh

Yes, this isn't robust against whitespace, either PLUS it's
inefficient. But in some cases the find ... | sed ... | sh pattern
is quite useful.

Ciao,
Kili