The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to find a file named vijay in a directory using find command amirthraj_12 UNIX for Dummies Questions & Answers 6 10-25-2008 09:37 AM
Find files size 0 within a directory astonmartin Shell Programming and Scripting 3 02-07-2008 01:49 PM
command to find out total size of a specific file size (spread over the server) abhinov SUN Solaris 3 08-08-2007 03:48 AM
How find size of directory truth HP-UX 2 12-07-2005 06:12 PM
size of a directory collins High Level Programming 6 10-15-2004 02:08 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-24-2008
Registered User
 

Join Date: Jul 2007
Posts: 21
Find the size of a directory

Hi,

I would really appreciate if you could help me with this. I have a directory structure like this :-
/data
Under data i have directories /data1 , /input_files , /output_files etc . Under these directories I have other subdirectories.

What i am looking for is to find out the size of all the directories under /data.

for example, if i do du -s /data/data1, i get : -
du -s /data/data1
2 /data/data1

I am looking for somtihng which will give me size of all the directories in /data.

Thanks in advance
Reply With Quote
Forum Sponsor
  #2  
Old 01-24-2008
dj -------
 

Join Date: Feb 2007
Location: Cochin/Bangalore, India
Posts: 439
Try this:

ls -lR | egrep '^d|^-' | awk '{ sum=sum+$5; }END{print sum}'
Reply With Quote
  #3  
Old 01-24-2008
Registered User
 

Join Date: Jan 2008
Posts: 52
I think you can use du command combined with -s option
man du
Reply With Quote
  #4  
Old 01-24-2008
Registered User
 

Join Date: Jan 2008
Posts: 7
How about a 'bigdu' script

I solved this problem so many times I finally wrote a real script, it allows summing of the directory content sizes down to level N:

http://www.theneills.org/src/scripts/bigdu.ksh

--
Qman
Reply With Quote
  #5  
Old 01-24-2008
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 737
Quote:
Originally Posted by divz View Post
What i am looking for is to find out the size of all the directories under /data.
For the grand total use:
Code:
du -hs /data
If you need the size of each directory under data use find:
Code:
find /data -type d -exec du -hs {} \;
Reply With Quote
  #6  
Old 01-24-2008
Registered User
 

Join Date: Jul 2007
Posts: 21
Thanks a lot guys. I kind of figured it out. This is what i did

for i in `ls -F | grep '/$'` ; do
du -s `echo "/data/$i"`
done

This gives the required result
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 06:40 AM.


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