I have a cron job set to delete everything in a garbage directory every day. Most of the time it works, but once last week, and again today, for what appears to be no reason it didn't work. My cron: rm -rf /home/accountname/garbage/* The error I got (via email) /bin/sh: /bin/rm: Argument list too long Any ideas?
It depends. Sometimes 500, sometimes 1500+. Depends on how much traffic the site gets per day. The directory is used for a cache.
are you using wildcards? otherwise, have the email also send you the argument list. maybe the obvious has happened and the diagnostic message really is telling the truth. too many file names for the command to run.
You're reaching the max # of files that can be listed in the rm queue if my memory serves me right. The solution to this is to use a command like find to grab the files and then pipe them over to rm so it can remove them at a more reasonable level at a time. So I believe this would do the trick find /home/accountname/garbage/ -type f -maxdepth 1 | xargs rm -n100 n will control the number of arguments to send to rm and it does not delete other directories or symbolic links. Of course I make no guarantee this will work best to test it of course before running it in a live environment.