LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-10-2003, 07:47 PM   #1
riddlebox80
CL volunteer
 
Registered: Jul 2002
Location: illinois
Distribution: Collegelinux and Libranet
Posts: 105

Rep: Reputation: 15
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
 
Old 06-10-2003, 08:33 PM   #2
AltF4
Member
 
Registered: Sep 2002
Location: .at
Distribution: SuSE, Knoppix
Posts: 532

Rep: Reputation: 31
try "du -s -k /some/directory/here" and parse the result
 
Old 06-11-2003, 06:51 AM   #3
riddlebox80
CL volunteer
 
Registered: Jul 2002
Location: illinois
Distribution: Collegelinux and Libranet
Posts: 105

Original Poster
Rep: Reputation: 15
I'm sorry but I dont even know what parse the results means?
thanks for the help though
 
Old 06-11-2003, 06:58 AM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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
 
Old 06-11-2003, 01:13 PM   #5
riddlebox80
CL volunteer
 
Registered: Jul 2002
Location: illinois
Distribution: Collegelinux and Libranet
Posts: 105

Original Poster
Rep: Reputation: 15
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.
 
Old 06-11-2003, 01:21 PM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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
 
Old 06-11-2003, 01:36 PM   #7
riddlebox80
CL volunteer
 
Registered: Jul 2002
Location: illinois
Distribution: Collegelinux and Libranet
Posts: 105

Original Poster
Rep: Reputation: 15
thanks again for the help that should work for me thanks and sorry for not explaining it the right way.
 
Old 06-11-2003, 07:27 PM   #8
riddlebox80
CL volunteer
 
Registered: Jul 2002
Location: illinois
Distribution: Collegelinux and Libranet
Posts: 105

Original Poster
Rep: Reputation: 15
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to determine # files in a directory ElricM Linux - Newbie 9 01-24-2012 02:37 PM
Script to delete files with 0k file size in a directory justgiver Linux - Newbie 4 01-28-2008 04:56 AM
Which directory contains files that normally change their size frequently? Simon Adebisi Linux - Software 4 06-28-2005 03:37 PM
finding size of total files in a directory blackzone Linux - Newbie 3 01-07-2005 03:01 AM
To know the size of all files in a directory ganninu Linux - General 6 08-01-2003 12:33 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration