LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   trying to determine the size of all files in a directory (https://www.linuxquestions.org/questions/programming-9/trying-to-determine-the-size-of-all-files-in-a-directory-64874/)

riddlebox80 06-10-2003 07:47 PM

trying to determine the size of all files in a directory
 
How would I write a script that will determine if all the files in a directory are below say 650mb, and if they are more than 650mb maybe say some sort of error?
Thanks for all help

AltF4 06-10-2003 08:33 PM

try "du -s -k /some/directory/here" and parse the result

riddlebox80 06-11-2003 06:51 AM

I'm sorry but I dont even know what parse the results means?
thanks for the help though

acid_kewpie 06-11-2003 06:58 AM

read up on "find", e.g

find /directory -size +650000k

will find all files that are over 650mb, then you can use an -exec option (or a thousand other ways) to run a command on each of those files or such like.

for details on beginning scripting, read through some of the Rute guide in my signature, and the bash-scripting howto at tldp.org

riddlebox80 06-11-2003 01:13 PM

this is what I am doing, I am writing a script to burn audio cds, so now it will convert all mp3 files in .wav files normalize them and burn them but I have no clue if there are too many files in the directory to make the cd, so I would like it to check and tell me if there are to many files in that directory...sorry I waited till now to tell you all this.

acid_kewpie 06-11-2003 01:21 PM

so it's the total size that matters... nice to finally know what we're meant to be solving.

so just check a du output. assuming that there will never be any subdirectories around, this should work.
Code:

if [ `/bin/du $1 -s | cut -f1` -lt 650000 ]
then
  echo less than 650mb
else
  echo more than 650mb
fi


riddlebox80 06-11-2003 01:36 PM

thanks again for the help that should work for me thanks and sorry for not explaining it the right way.

riddlebox80 06-11-2003 07:27 PM

sorry for this but everytime I run the script it tells me that there is more than 650mb when there is 606mb in the directory? Thanks for the help and patients


All times are GMT -5. The time now is 08:09 AM.