Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

deleting files based on size 1

Status
Not open for further replies.

czarj

Technical User
Apr 22, 2004
130
US
I'm looking to write a script to remove subdirectories from a directory based on size. In my directory of interest I have one or two subs with a file size almost ten times greater than the ones I want to delete.

I realize I can probably set up somthing with the "du" command, but I'm not sure. Any help would be appreciated.

thanks
 
You want to delete files or directories ?
If files is a goal then man find.
If directories, then du -rsk is a good approach.
What have you so far ?

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
PH,

The goal is to delete only subdirectories under a certain file size (say 15MB). I'm just not sure how to set up a script to do that in unix (i'm not a Unix person).

thanks,

czarj
 
#find_big files
if [ $# -lt 1 ]; then
echo "USAGE: $0 <starting directory>"
exit
fi
find $1 -size +1000000c -print -exec ls -la {} +
find $1 -size +1000000c -exec rm {} +


 
Script to find directories under a certain size:
Code:
#!/usr/bin/ksh

cd /path/to/sub-dirs

du -sk *|while read size name
do
    if [ -d $name ] && [ $size -lt 15000 ]
    then
        echo directory $name size $size KB
        # put code here to delete
    fi 
done
 
Excellent,

Thanks everybody!!!!!!!!


CzarJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top