home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!caen!sdd.hp.com!think.com!barmar
- From: barmar@think.com (Barry Margolin)
- Newsgroups: comp.unix.questions
- Subject: Re: Question: which is faster 'find -exec' or 'find | xargs' ??
- Date: 4 Sep 1992 21:49:11 GMT
- Organization: Thinking Machines Corporation, Cambridge MA, USA
- Lines: 27
- Message-ID: <188lknINNotr@early-bird.think.com>
- References: <1992Sep4.041033.23158@news.acns.nwu.edu>
- NNTP-Posting-Host: telecaster.think.com
-
- In article <1992Sep4.041033.23158@news.acns.nwu.edu> navarra@casbah.acns.nwu.edu (John Navarra) writes:
- >I was experimenting with find and xargs. I issued the command
- > find . -exec ls -ld {} \;
- >and the command
- > find . -print | xargs ls -ld
-
- >Question: why is the xargs command MUCH faster?
-
- The -exec version executes a separate ls command for each file that is
- found. The xargs version accumulates a bunch of arguments and then
- executes one ls command with all of them. The difference is all the time
- spent starting up new shell and ls processes. It's the difference between:
-
- sh -c "ls file1"
- sh -c "ls file2"
- sh -c "ls file3"
- sh -c "ls file4"
- sh -c "ls file5"
-
- and
-
- sh -c "ls file1 file2 file3 file4 file5"
- --
- Barry Margolin
- System Manager, Thinking Machines Corp.
-
- barmar@think.com {uunet,harvard}!think!barmar
-