On Sunday 17 July 2011 16:23:54 Grant did opine thusly:
> > way around "Argument list too long"?:
> >> My crontab deletes all files of a certain type in a certain
> >> folder with yesterday's date in the filename.  It usually
> >> executes but sometimes fails with:
> >> 
> >> /bin/rm: Argument list too long
> >> 
> >> What would you do about this?
> > 
> > Use find with the -delete option.
> 
> I'm getting the same thing from find:
> 
> $ /usr/bin/find /home/user/*-`/bin/date -d 'yesterday'
> +\%Y\%m\%d`*.jpg /usr/bin/find: Argument list too long
> 
> $ /usr/bin/find -delete /home/user/*-`/bin/date -d 'yesterday'
> +\%Y\%m\%d`*.jpg /usr/bin/find: Argument list too long
> 
> $ /usr/bin/find /home/user/*-`/bin/date -d 'yesterday'
> +\%Y\%m\%d`*.jpg|xargs rm /usr/bin/find: Argument list too long
> rm: missing operand
> Try `rm --help' for more information.

You are doing it wrong.

Each command has something between ``, so bash is expanding that 
entire list and just before feeding the whole lot to find, realizes 
that the list is longer than 65,536 characters. It's bash that is 
returning that error, not find.

You're mistake is trying to marrow down *where* find should look 
instead of *what* it should look for.

You something like this:

find /home/user -type f -name "`/bin/date -d 'yesterday' 
+\%Y\%m\%d`*.jpg`"

See the difference? That will not produce a gigantic command line, it 
will produce a rather short one and find will check each file it finds 
one by one and see if it's name matches the supplied pattern.

Word of warning: DO NOT blindly run -delete on this, first check the 
total output and make sure it only has what you want to delete. As 
with all things concerning rm or file deletion, the burden rests on 
you to make completely sure you delete only what you want to delete.


-- 
alan dot mckinnon at gmail dot com

Reply via email to