Question on directory size


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Question on directory size
# 1  
Old 02-19-2010
Java Question on directory size

Hi All,

Please clarify me on the below:

/home/arun>ls -l
drwxrwxrwx 2 arun system 1024 Oct 06 2009 - arun_req

/home/arun>cd arun_req
/home/arun/arun_req>ls -l
-rw-rw--w- 1 arun system 570 Oct 06 2009 paramfile1
-rw-rw--w- 1 arun system 570 Oct 06 2009 paramfile2

/home/arun/arun_req>rm paramfile1
/home/arun/arun_req>cd ..
/home/arun>ls -l
/home/arun>
drwxrwxrwx 2 arun system 1024 Oct 06 2009 - arun_req

i noticed that the directory size is not reduced even after the file inside the directory got deleted. can you please explain me...

Thanks.

# 2  
Old 02-19-2010
are you sure about the deleting of the file ????
# 3  
Old 02-19-2010
Error

1024 is *not* the disk size - that is easy to verify by creating a large file in a directory:

Code:
jonas merzky /tmp : mkdir test
jonas merzky /tmp : ls -ld test
drwxr-xr-x  2 user group  68 Feb 19 09:36 test/
jonas merzky /tmp : du -sh test
  0B	test

jonas merzky /tmp : touch test/null
jonas merzky /tmp : ls -ld test
drwxr-xr-x  3 user group  102 Feb 19 09:37 test/
jonas merzky /tmp : du -sh test
  0B	test

jonas merzky /tmp : dd if=/dev/random of=test/data count=1024000
jonas merzky /tmp : ls -ld test
drwxr-xr-x  4 user group 136 Feb 19 09:37 test/
jonas merzky /tmp : du -sh test
500M	test

You'll see that the 'size' reported by ls is changing only slightly: this specifies the space the directory metadata is occupying in the file system, such like the inodes needed to specify the directory structure. The above is on a macOS file system, so that looks somewhat different than a Linux/ext2 one which I guess you are using.

To obtain the size of the directory, use 'du' (Disk Usage), as shown above. 'man du' for more command line switches.

Cheers, Andre.
# 4  
Old 02-19-2010
Once allocated directory size displayed by ls will not be reduced even if the contents will be deleted. It will still show the large size it formerly needed as Andre described.

Though a du does not show different output:
Code:
$> ll tmp
total 280
drwxr-xr-x 2 root root  278528 2010-02-19 09:34 .
drwxr-xr-x 3 root root   4096 2010-02-19 09:09 ..
$> ll| grep tmp
drwxr-xr-x 2 root root  278528 2010-02-19 09:34 tmp
$> ls -la tmp
total 280
drwxr-xr-x 2 root root  278528 2010-02-19 09:34 .
drwxr-xr-x 3 root root   4096 2010-02-19 09:09 ..
$> du -sk tmp
276     tmp

This is a Linux box using ext3. It could be that other OS'es and fs'es might behave different. To change that back you'll have to delete and recreate the directory.

JFS2 on AIX resizes the size dynamically after contents are deleted, just as a side note.
# 5  
Old 02-19-2010
Lightbulb

HFS seems to resize, too:

Code:
jonas /tmp : mkdir test
jonas /tmp : l -d test
drwxr-xr-x  2 user group  68 Feb 19 09:58 test/

jonas /tmp : touch test/null
jonas /tmp : l -d test
drwxr-xr-x  3 user group  102 Feb 19 09:58 test/

jonas /tmp : rm test/null 
jonas /tmp : l -d test
drwxr-xr-x  2 user group  68 Feb 19 09:58 test/

I guess ext3 is doing some caching, or lazy garbage collection - but don't know really :-P Interesting though!
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. UNIX for Advanced & Expert Users

question about size of a directory

Hi, when I do ls -ld to a directiry I see the size of directory as 1024. Does this mean my directory occupies 1024 blocks? What does exactly 1024 specify? But when I do du -sk to directory it shows 9k. any clarifications gurus? -Ashish (1 Reply)
Discussion started by: shriashishpatil
1 Replies

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

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

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