hugme: (Default)
[personal profile] hugme
I 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...

Profile

hugme: (Default)
hugme

April 2011

S M T W T F S
     12
3456789
10111213141516
17 181920212223
24252627282930

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Apr. 8th, 2026 06:24 am
Powered by Dreamwidth Studios