home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / unix / question / 10749 next >
Encoding:
Internet Message Format  |  1992-09-07  |  1.3 KB

  1. Path: sparky!uunet!caen!sdd.hp.com!think.com!barmar
  2. From: barmar@think.com (Barry Margolin)
  3. Newsgroups: comp.unix.questions
  4. Subject: Re: Question: which is faster 'find -exec' or 'find | xargs' ??
  5. Date: 4 Sep 1992 21:49:11 GMT
  6. Organization: Thinking Machines Corporation, Cambridge MA, USA
  7. Lines: 27
  8. Message-ID: <188lknINNotr@early-bird.think.com>
  9. References: <1992Sep4.041033.23158@news.acns.nwu.edu>
  10. NNTP-Posting-Host: telecaster.think.com
  11.  
  12. In article <1992Sep4.041033.23158@news.acns.nwu.edu> navarra@casbah.acns.nwu.edu (John Navarra) writes:
  13. >I was experimenting with find and xargs. I issued the command
  14. >  find . -exec ls -ld {} \;
  15. >and the command
  16. >  find . -print | xargs ls -ld
  17.  
  18. >Question: why is the xargs command MUCH faster?
  19.  
  20. The -exec version executes a separate ls command for each file that is
  21. found.  The xargs version accumulates a bunch of arguments and then
  22. executes one ls command with all of them.  The difference is all the time
  23. spent starting up new shell and ls processes.  It's the difference between:
  24.  
  25.     sh -c "ls file1"
  26.     sh -c "ls file2"
  27.     sh -c "ls file3"
  28.     sh -c "ls file4"
  29.     sh -c "ls file5"
  30.  
  31. and
  32.  
  33.     sh -c "ls file1 file2 file3 file4 file5"
  34. -- 
  35. Barry Margolin
  36. System Manager, Thinking Machines Corp.
  37.  
  38. barmar@think.com          {uunet,harvard}!think!barmar
  39.