Re: xargs verses exec

From: Rich Jesse <>
Date: Tue, 24 Jul 2012 14:18:58 -0500 (CDT)
Message-ID: <>

Joel writes:

> find */cdump -name "*.abc" -type f -mtime +40 -print | xargs ls -ltr
> Then, the find command comes back with the contents of the ${ORACLE_BASE}
> directory.
> If I replace "ls -ltr" with "rm", I can see that this could be dangerous.
> (Maybe removing something not intended).

A few things here. You're globbing parameters to the find command with the "*/cdump" (which I couldn't even do on AIX 5.3). I think you'd be better off using the -prune option, which may solve your issue. Google and some man pages should come up with examples for you.

Also, most implementations of xargs have the "-i" option to take the output from the find and substitute into your command with curly braces like:

    blah|xargs -i ls -ltr {}

This shouldn't be strictly necessary in most cases (that I can think of), but like your "-print" option, it offers control, maintenance considerations, documentation, etc. And you can couple it with the "-t" option for a "trace" of what the xargs command is actually doing, which is helpful for log files in a cron'd script.

HTH! GL! Rich

Received on Tue Jul 24 2012 - 14:18:58 CDT

Original text of this message