Find the size of a directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find the size of a directory
# 1  
Old 01-24-2008
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
Smilie
# 2  
Old 01-24-2008
Try this:

ls -lR | egrep '^d|^-' | awk '{ sum=sum+$5; }END{print sum}'
# 3  
Old 01-24-2008
I think you can use du command combined with -s option
man du
# 4  
Old 01-24-2008
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
# 5  
Old 01-25-2008
Quote:
Originally Posted by divz
What i am looking for is to find out the size of all the directories under /data.
Smilie
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 {} \;

# 6  
Old 01-25-2008
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 Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Ls directory size reporting byte size instead of file count

I have been searching both on Unix.com and Google and have not been able to find the answer to my question. I think it is partly because I can't come up with the right search terms. Recently, my virtual server switched storage devices and I think the problem may be related to that change.... (2 Replies)
Discussion started by: jmgibby
2 Replies

2. Shell Programming and Scripting

Find a particular directory in multiple file systems and calculate total size

Hello : I need some help in writing a ksh script which will find a particular directory in all the file systems in a server and finally report the total size of the direcotry in all the file systems. Some thing like this.. find /u*/app/oracle -type d -name "product" -prune and then... (1 Reply)
Discussion started by: Sam1974
1 Replies

3. Shell Programming and Scripting

How to delete some of the files in the directory, if the directory size limits the specified size

To find the whole size of a particular directory i use "du -sk /dirname".. but after finding the direcory's size how do i make conditions like if the size of the dir is more than 1 GB i hav to delete some of the files inside the dir (0 Replies)
Discussion started by: shaal89
0 Replies

4. Shell Programming and Scripting

Find which dir is big size in a directory

Hi all, Could you please tellme the commadn which sorts the list of directories in a parent dir by their size. Thanks. (2 Replies)
Discussion started by: firestar
2 Replies

5. Shell Programming and Scripting

find size, cp breaks directory structure

I'm using this now: find /some/path/with/sourcefiles -type f -size -7M -exec /bin/cp -uv {} /some/path/ \; but it doesn't preserve the directory structure, also I've tried it with find /some/path/with/sourcefiles -type f -size -7M -exec /usr/bin/rsync -auv {} /some/path/ \; but that doesn't... (9 Replies)
Discussion started by: unclecameron
9 Replies

6. Solaris

Directory size larger than file system size?

Hi, We currently have an Oracle database running and it is creating lots of processes in the /proc directory that are 1000M in size. The size of the /proc directory is now reading 26T. How can this be if the root file system is only 13GB? I have seen this before we an Oracle temp file... (6 Replies)
Discussion started by: sparcman
6 Replies

7. Shell Programming and Scripting

find with file size and show the size

Hi All... is the below command be modified in sucha way that i can get the file size along with the name and path of the file the below command only gives me the file location which are more than 100000k...but I want the exact size of the file also.. find / -name "*.*" -size +100000k ... (3 Replies)
Discussion started by: rpraharaj84
3 Replies

8. Shell Programming and Scripting

how to find the size of a directory alone

hi, i am using korn shell............... Any one please help me in solving the below question: question: i need to find the size of the directory alone... let us assume /root/kamal/hash1 is the directory, now i want to find the hash1 size .. ... (7 Replies)
Discussion started by: G.K.K
7 Replies

9. Solaris

command to find out total size of a specific file size (spread over the server)

hi all, in my server there are some specific application files which are spread through out the server... these are spread in folders..sub-folders..chid folders... please help me, how can i find the total size of these specific files in the server... (3 Replies)
Discussion started by: abhinov
3 Replies

10. HP-UX

How find size of directory

Hi, How can find the size of the directory. If the directory has 1000 files. I want the total size of directory including all the files. the bdf command is just able to give only the volume size. It is not heling my cause. (2 Replies)
Discussion started by: truth
2 Replies
Login or Register to Ask a Question