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
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
A directory entry is a name and an inode number. A directory is a file that contains a collection of these entries. If I create a new directory, it will be rather small. If I cd into it and create 5 100GB files, my directory continues to be small... after all it only has 7 entries at this point.
Please clarify if you are discussing the size of a directory or the collective total of disk space used by a directory and all files and subdirectories contained within it.
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
#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
find . -type d -size +300c -print
Would report all of these directories.
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.
du -ok .
reports the size of all directories below . in kbytes
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.
"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.
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.