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:
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
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":
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.