[rt-users] rm sessiondata from crontab...

Bruce Campbell bruce_campbell at ripe.net
Fri Jan 18 15:48:34 EST 2002


On Fri, 18 Jan 2002, Ferguson, Kevin wrote:

> /usr/bin/find /opt/rt2/WebRT/sessiondata -type f -amin +600 -print |
> /usr/bin/xargs /bin/rm
>
> xargs will accrue as much input as possible that will fit on a single
> command line and pass that to /bin/rm in one swell foop.  Voila, one call
> to /bin/rm to delete many files.  HTH.

Just a general observation, when using find and xargs together, you may
run into files with spaces or other weird characters in them.  Not a
problem in this specific case, however it is generally better to:

	find directory -type f (various conditions) -print0 |
	xargs -0 -r rm

The '-print0' to find and '-0' to xargs are 'print results terminated with
the NULL character' and 'input arguments are terminated with the NULL
character'.  Otherwise, if
files-with-spaces-and-other-shell-seperation-characters are present, then
xargs will bomb out in an interesting fashion.

The '-r' option simply disables the running of your command (rm) if there
is no input from find (no matching files).  Otherwise, rm will print a
highly-helpful message of 'too few arguments' or something similar.

One you have run your routine cleanup command a few times, put it into the
appropriate crontab (NOT ROOT), and remember to pipe both the stdout and
stderr to /dev/null, unless you really want to see what a known command
produces each time it runs.

--==--
Bruce.

Thank-you for watching Useful Little Known Unix Tricks; Spotlight on
Xargs.  Next week on the show, we will be demonstrating how little
awk(ward) programs can ease your routine script maintainence.







More information about the rt-users mailing list