Parameter List to Long

I am trying to do a find file command on a directory and delete files older then 30 days and I am getting an error saying that the parameter list that I am passing to the rm command is to long. Here is my command:

find ~mydir/* -type f -mtime +$30 | xargs -i -exec rm -rf {} \;

ksh: /bin/find: 0403-027 The parameter list is too long.

What do I do to fix this?

i'm assuming this script hasn't been run for awhile, I'm not sure what the limit of the number of files rm can process, try and up the number of days to 50 or 60 to remove some of the files and then try the 30? I would imagine there is a better way but this is 1 thing to try

Try running it like this:

find ~mydir -type f -mtime +$30 | xargs -i -exec rm -rf {} \;

Notice no /* in find... the shell is trying to expand the * into all of the file/directories in mydir. If you want to keep the /* there, you might try using "quotes":

find ~"mydir/*" -type f -mtime +$30 | xargs -i -exec rm -rf {} \;

Hope this helps.

I use this routine a lot, try this: this is ksh

cd directoryname
filelist=`find directoryname/* -type f -mtime +n`
for x in $filelist
do
rm $x
done

This will clean you up the first time, and then after that you may have a smaller parm list to work with. otherwise, wash,rinse,repeat.

When I am testing a script like this, I include the set -x and echo the commands first to see what it will really remove before actually letting it remove files.

Good Luck.