Operating System - HP-UX
1833860 Members
2033 Online
110063 Solutions
New Discussion

ls -l bytes column for Directories ....

 
SOLVED
Go to solution
Ezhilarasan
Occasional Advisor

ls -l bytes column for Directories ....

Hi,

In the command ls -l, what does bytes column
represent for directories ? For files it shows actual size.
But for directories, what it means, any logic
behind this ?

Thanks
R. Ezhil
4 REPLIES 4
RikTytgat
Honored Contributor
Solution

Re: ls -l bytes column for Directories ....

Hi,

The directory 'file' contains the names of the files that are in the directory, and the inode of the file. Since files are assigned blocks (and a directory is a file), and blocks are of limited size, a directory can be assigned multiple blocks when a lot of files are in the directory.

This explains the size of a directory 'file'.

Hope this answers your question.

Rik.
Jdamian
Respected Contributor

Re: ls -l bytes column for Directories ....

You can type the following commands to check that...

cd /tmp
mkdir example
cd example

ll -d . #you'll see the size of this dir.

integer i=100
while (( i>0 ))
do
touch i
i=i-1
done


ll -d . #you'll see the dir size has increased.

john korterman
Honored Contributor

Re: ls -l bytes column for Directories ....

Hi Ezhil,
as Rik pointed out the directory holds the name of the files in it. If you change Damiens example a little, you can see that more clearly. Try changing the line
touch i
to
touch ${i}abcdefg
which will create 100 files whose names end in the string "abcdefg".
Then display the content of the examples directory:
# strings .
and you should see 100 lines flashing by. If you then delete the beforementioned 100 files and repeat
# strings .
you will see same 100 lines flashing by. Although the files have been deleted from the directory, their entries in the directory file are not deleted, just marked as "free".
Then touch a new file, e.g.:
# touch flipflap
and repeat
# strings .
and you will see 100 lines flashing by again, this time flipflap has taken one of the "free" entries in the directory. Hence the size of a directory reflects the biggest size it has had in its entire lifetime.

regards,
John K.
it would be nice if you always got a second chance
Chris Wilshaw
Honored Contributor

Re: ls -l bytes column for Directories ....

Another point is that the "size" of a directory may not be the current size. It shows the maximum that has been reached - it can only ever be seen to increase, never decrease.

eg:

mkdir test
ll | grep test
>>>>>> 96 Jan 24 10:32 test

cp /stand/vmunix* test
ll | grep test
>>>>>> 1024 Jan 24 10:33 test

rm test/vmunix*
ll | grep test
>>>>>> 1024 Jan 24 10:34 test

ll test
total 0