The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
size of directory redbeard_06 Shell Programming and Scripting 19 08-08-2008 01:08 AM
size of directory with ls -l pascalbout AIX 2 02-21-2006 12:21 PM
size of a directory collins High Level Programming 6 10-15-2004 02:08 PM
size of a directory? yls177 UNIX for Dummies Questions & Answers 2 11-25-2002 06:44 AM
Size of a directory minazk Shell Programming and Scripting 9 10-01-2002 03:03 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 06-28-2007
Registered User
 

Join Date: Apr 2007
Posts: 23
Size of Directory

I have a C program to find out the total size of all the files in a directory.

So what it does is.. it scans through all the files in the directory and does a stat() on each of them and sums up the size returned by st_size .

Is there a quicker way to do this.. without doing a stat() on each one of them ? Basically I want to find the total size occupied by all files in a directory

thanks,
the tantric !
Reply With Quote
Forum Sponsor
  #2  
Old 06-28-2007
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,658
There is no quicker way to do it. And doing it right might be a bit harder than that. Consider:
Code:
$ echo stuff > file1
$ ln file1 file2
$ ls -is1 file1 file2
79074 1 file1
79074 1 file2
$
Is it ok to count both file1 and file2? They point to the same inode, so there is only one copy of the data.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:53 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0