Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Blog | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Looking for a quick script solution



Gordon Marx wrote:
> Richard Pieri wrote:
>> This finds all files in the current directory...and execs gunzip on
>> each one.
> 
> That's actually the behavior of find's -exec option. xargs is smarter
> than that -- it executes command lines that are as near as possible to
> the maximum length each time.

I've noticed that newer versions of find actually support an extension 
to -exec that emulates xargs (from the GNU find version 4.2.32 man page; 
note the trailing "+"):

   -exec command {} +
     This  variant  of  the -exec option runs the specified command on
     the selected files, but the command line is  built  by  appending
     each  selected  file name at the end; the total number of invoca-
     tions of the command will be much less than the number of matched
     files.  The command line is built in much the same way that xargs
     builds its command lines.  Only one instance of {}  is   allowed
     within  the  command.   The  command  is executed in the starting
     directory.

The same man page also recommends using -execdir over -exec, as there 
"are unavoidable security problems surrounding use of the -exec option," 
and that -execdir "avoids race conditions during resolution of the paths 
to the matched files." Although it seems to open up another hole: "If 
you use this option, you must ensure that your $PATH environment 
variable does not reference the current directory; otherwise, an 
attacker can run any commands they like by leaving an 
appropriately-named file in a directory in which you will run -execdir."

-execdir uses the same syntax, but does a CWD to the directory 
containing the file being acted on before performing the operation. But 
note that the batching performed by the "+" extension would be limited 
to files in a single directory, so if your files happen to be widely 
dispersed in a file system, you'll get a lot of separate exec() calls.

  -Tom

-- 
Tom Metro
Venture Logic, Newton, MA, USA
"Enterprise solutions through open source."
Professional Profile: http://tmetro.venturelogic.com/






BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org