file delete by size....
Apr. 24th, 2001 10:23 amI had someone ask on the list how to delete files in a directory by size... hrm, find is a nice command however it's a pain in the ass when you try and give it a group of sizes or dates to go though... I wrote this yesterday to delete all of the files more than 7 days old the current directory
X=7
while [ "$X" -lt "100" ]; do
find . -ctime $X -exec rm -f {} ";"
X=$((X+1))
doneX=7
this will delete every file in current directory between 7 and 100 days old with size it's the same thing:
X=3000000
while [ "$X" -lt "8000000" ]; do
find . -size "$X"c -exec rm -f {} ";"
X=$((X+1))
done
this will delete every file in a directory between 3 and 8 meg; however it will take a LONG time to run (find commands arn't quick), you will want somthing a little bit more effeciant so try this one:
rm -f `ls -al | awk '$5 ~ /^[3-8]......$/ {print $9}'`
there you are 2 ways to do it...
X=7
while [ "$X" -lt "100" ]; do
find . -ctime $X -exec rm -f {} ";"
X=$((X+1))
doneX=7
this will delete every file in current directory between 7 and 100 days old with size it's the same thing:
X=3000000
while [ "$X" -lt "8000000" ]; do
find . -size "$X"c -exec rm -f {} ";"
X=$((X+1))
done
this will delete every file in a directory between 3 and 8 meg; however it will take a LONG time to run (find commands arn't quick), you will want somthing a little bit more effeciant so try this one:
rm -f `ls -al | awk '$5 ~ /^[3-8]......$/ {print $9}'`
there you are 2 ways to do it...