size of directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting size of directory
# 8  
Old 02-27-2007
Quote:
Originally Posted by redbeard_06
Hello again;

I have a directories and subdirectories in my current directory and i wanna to find the directories( and subdirectories ) which are larger than what user enters as first parameter.

find . -type d -size +"$1"c -print > directories.dat

I used this command and i am not sure it is working properly.
Because i entered the
./myprog.sh 300
and it found empty directory.

Or i entered the
./myprog.sh 500000
and it found nothing however in the current directory i have directories which are larger than 500000 bytes

i wonder this command are working for directory search or not working

Thanks for your replies..
The command:

Code:
find . -type d -size +"$1"c -print

searches for directories for which the data block which contain the information of the directory have a size greater than the value as specified by the argument.

The command provides no information about the size of the files located within the directory.

It checks for the size as reported by the "ls -l" command
Code:
#ls -l
drwxr-xr-x  10 user     group       11264 Feb 27 03:10 dir1
drwxr-xr-x  10 user     group          512 Feb 28  2006 dir2
drwxr-xr-x   2 user     group         1536 Feb 27 04:00 dir3
drwxr-xr-x   2 user     group          512 Nov 10 16:35 dir4

So the size of:
dir1 = 11264
dir2 = 512
dir3 = 1536
dir4 = 512

Code:
find . -type d -size +300c -print

Would report all of these directories.

Code:
find . -type d -size +50000c -print

Would report none of these directories.

In neither case it wouldn't provide any information about the size of the files located inside the directory.

When a directory is created it has a default size of 512 (1 block).

When we start creating new files within this directory, at some stage the data block doesn't have enough space any more to store all the information about the files located within it.

The directory will increase in size because it will allocate an extra data block to store the information of files located within it.

The size of the directory will then show as 1024.

In the example above, dir1 has a size of 11264 (22 blocks). This means that at some stage an enormose amount of files were located within this directory.

When the number of files within a directory decreases, and the directory wouldn't need as many blocks any more to store the information about the remaining files, the size of the directory remains unchanged. No blocks are released. The data blocks will just have a lot of "empty" space.

So a directory with a big size doesn't need to contain a lot of files. However at some stage it did contain a lot of files. At the present the directory could even be empty.

To calculate the size of all files within a directory we will need a different approach.

Code:
du -ok .

reports the size of all directories below . in kbytes

Last edited by sb008; 02-27-2007 at 02:42 PM..
# 9  
Old 02-27-2007
Quote:
Originally Posted by redbeard_06
i cannot understand your code in addition i wrote this in my program and i does not work too.
İ wanna know that why this code is not working properly and where am i wrong?And how can i fix it?

find . -type d -size +"$1"c -print > directories.dat

İ have many directories and subdirectories in my current directory and i wanna list them (which are bigger) in directories.dat file.
That is all Smilie
Your command actually reports the size of your current directory if the size is greater than specified and NOT the size of the files/sub directories within it. Remember that the size of dir is different from the size of files within it.

But when you specify "depth" option with find, it acts on the contents of the directory first. Thats why you get the result.
# 10  
Old 02-27-2007
Quote:
Originally Posted by Deal_NoDeal
Your command actually reports the size of your current directory if the size is greater than specified and NOT the size of the files/sub directories within it. Remember that the size of dir is different from the size of files within it.

But when you specify "depth" option with find, it acts on the contents of the directory first. Thats why you get the result.
if we have a directory structure:

dir1/dir2/dir3

then

"find" without the "-depth" option will act on the directories in this order:

dir1
dir1/dir2
dir1/dir2/dir3

"find" with the "-depth" option will act on the directories in this order:

dir1/dir2/dir3
dir1/dir2
dir1

However in both scenarios we get information about the size of data blocks related to the directory and NOT of the files located within it.

The "-depth" option is irrelevant and will give wrong results either way, just in a different order.

After all the option "-type d" is specified, so files are totally ignored.

Leaving out the option "-type d", will report about files as well, however on an individual base, and not about the total size of all files within a specific directory or tree.

So using the option "-type d" will not change the outcome.
# 11  
Old 02-27-2007
Quote:
Originally Posted by sb008
if we have a directory structure:

dir1/dir2/dir3

then

"find" without the "-depth" option will act on the directories in this order:

dir1
dir1/dir2
dir1/dir2/dir3

"find" with the "-depth" option will act on the directories in this order:

dir1/dir2/dir3
dir1/dir2
dir1

However in both scenarios we get information about the size of data blocks related to the directory and NOT of the files located within it.

The "-depth" option is irrelevant and will give wrong results either way, just in a different order.

After all the option "-type d" is specified, so files are totally ignored.

Leaving out the option "-type d", will report about files as well, however on an individual base, and not about the total size of all files within a specific directory or tree.

So using the option "-type d" will not change the outcome.
Agreed. Was just explaining him why his code doesn't work. Using "du -sk" or so is the best way to get the correct result.
# 12  
Old 02-27-2007
Hello friends,
Thanks to all because of your complete and perfect explanations.
İ have been for 3days. And i have learnt many things( of course little things ) and i like linux and shell programming.

Well, does "du" have size comparision option? i looked at the "man du" but i didn not see any.
Because i wanna compare the size of directories( with subdirectories ) with the value as specified by the argument.
# 13  
Old 02-28-2007
Quote:
Originally Posted by redbeard_06
Hello friends,
Thanks to all because of your complete and perfect explanations.
İ have been for 3days. And i have learnt many things( of course little things ) and i like linux and shell programming.

Well, does "du" have size comparision option? i looked at the "man du" but i didn not see any.
Because i wanna compare the size of directories( with subdirectories ) with the value as specified by the argument.
You will need to get the "du -sk *" for all the dirs and files and then use it in a for loop or so to compare the size.
# 14  
Old 02-28-2007
But it did'n return the subdirectories?
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

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

3. Solaris

get directory size

Hi, How to get size of particular directory? Thanks (5 Replies)
Discussion started by: cutefriend
5 Replies

4. UNIX for Dummies Questions & Answers

directory tree with directory size

find . -type d -print 2>/dev/null|awk '!/\.$/ {for (i=1;i<NF;i++){d=length($i);if ( d < 5 && i != 1 )d=5;printf("%"d"s","|")}print "---"$NF}' FS='/' Can someone explain how this works..?? How can i add directory size to be listed in the above command's output..?? (1 Reply)
Discussion started by: vikram3.r
1 Replies

5. 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

6. UNIX for Dummies Questions & Answers

directory size with ls -l

am I right in assuming that in unix a directory size is just information about that directory stored somewhere on the file system, and not a sum of its contents? This is because ls -l gives 1024 as my directory size, when the directory contains many gigs worth of stuff. also, is du -sk dir ... (2 Replies)
Discussion started by: JamesByars
2 Replies

7. AIX

size of directory with ls -l

hello When i do a "ls -l" in a directory (Aix 5.3), i have the result : >ls -l total 65635864 -rw-r--r-- 1 lobi system 2559909888 Feb 20 15:06 cible5.7bdat -rw-r--r-- 1 lobi system 1020098870 Feb 20 13:06 cible6.7bdat -rw-r--r-- 1 lobi system 1544789511 Feb 20 11:06 cible9.7bdat -rw-r--r--... (2 Replies)
Discussion started by: pascalbout
2 Replies

8. Programming

size of a directory

hai friends I need a program to find the size of a directory.. When i tried to get the size, it always gives the default space allocated for it. How can i findout the exact size of a directory using a c program Thanks in advance Collins (6 Replies)
Discussion started by: collins
6 Replies

9. UNIX for Dummies Questions & Answers

size of a directory?

hi, say i have the following directory structure a/b/c/d... can i do df -kt /a/b/c/d and the output will gives me the total space of the directory space in d? or the output will just be the total space of the parent directory a. hope its clear.. (2 Replies)
Discussion started by: yls177
2 Replies

10. Shell Programming and Scripting

Size of a directory

Hi, It would be of great help if anyone can tell me what is the command for getting the size of a directory. Thx a lot in advance Minaz (9 Replies)
Discussion started by: minazk
9 Replies
Login or Register to Ask a Question