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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Program to selectively "du -sk" directories 3

Status
Not open for further replies.

saw

Technical User
Oct 6, 2000
14
US
I'm would like to do a "du -sk *" of a directory and for each line that produces, if the size of the directory is greater than 800MB, do a "du -sk" of that directory, then continue. Since this seems to be something that needs to be "line-based" rather than "word-based", I thought that maybe AWK could do it. The du, of course, prints out the size and the folder path as in:

382856 work/abc
725659 work/def
1338763 work/ghi

I'd like to take each line, and if the number is greater than 800000, then do 'du -sk' of that subdirectory, then continue.
Would I do this best with AWK?

thanks,
Scott
saw@ternion.com
 
not sure what you're trying to do, but here's something to think about:

Code:
#!/bin/ksh
typeset -i sizeTHR=800000
du -sk * | while read s dir
do
   if (( $s >= $sizeTHR )) ; then
      du -sk "${dir}"
   fi;
done

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Something like this ?
du -sk * | awk '{print;if($1>800000)system("du -sk "$2"/*")}'

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks Vlad and PH! Both ways work great.

Hey Vlad, how did you post your code in that cool "CODE" box?

thanks again,
Scott
 
To obtain this:
Code:
my code here
Type this:
[ignore]
Code:
my code here
[/ignore]

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks PH, too cool!

Here's what I ended up doing:
Code:
du -sk * | while read SIZE DIR
   do echo "$SIZE $DIR"
   if [ "$SIZE" -gt 800000 ]
      then du -sk $DIR/* | while read SUBSIZE SUBDIR
      do echo "   $SUBSIZE $SUBDIR"
      done
   fi
done

I apologize for this not ending up being, necessarily, an AWK thing. Thanks again, though, for everyone's help!

Scott
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top