KimVette |
12-10-2005 05:09 PM |
If you're trying to find out how much space is taken up by say, root (/) and its subdirectories, you will want to use the du (disk usage) command:
As far as the listed size of the directories is concerned, let's experiment, watching the directory size of /foo grow as we progress:
Code:
kimp4:/ # ls -l
total 40144
drwxr-xr-x 23 root root 568 2005-12-10 18:13 .
drwxr-xr-x 23 root root 568 2005-12-10 18:13 ..
drwxr-xr-x 2 root root 2920 2005-12-04 19:29 bin
drwxr-xr-x 3 root root 448 2005-12-04 19:49 boot
drwxr-xr-x 11 root root 16140 2005-12-09 15:52 dev
drwxr-xr-x 90 root root 7960 2005-12-09 15:52 etc
-rw-r--r-- 1 root root 41041920 2005-12-06 14:03 etc.tar
drwxr-xr-x 3 root root 72 2005-12-04 20:12 home
drwxr-xr-x 11 root root 4136 2005-12-05 02:19 lib
drwxr-xr-x 6 root root 192 2005-12-09 15:52 media
drwxr-xr-x 11 root root 280 2005-12-06 15:43 mnt
drwxr-xr-x 10 root root 264 2005-12-04 23:29 opt
dr-xr-xr-x 123 root root 0 2005-12-09 10:49 proc
drwx------ 14 root root 752 2005-12-10 18:10 root
drwxr-xr-x 3 root root 7976 2005-12-04 20:08 sbin
drwxr-xr-x 4 root root 96 2005-12-04 19:10 srv
drwxr-xr-x 2 root root 48 2005-09-09 05:59 subdomain
drwxr-xr-x 10 root root 0 2005-12-09 10:50 sys
drwxrwxrwt 25 root root 1816 2005-12-10 18:00 tmp
drwxr-xr-x 12 root root 344 2005-12-04 19:24 usr
drwxr-xr-x 14 root root 360 2005-12-04 19:14 var
drwxr-xr-x 5 root root 120 2005-12-06 15:38 windows
kimp4:/ # mkdir foo
kimp4:/ # ls -lha
total 40M
drwxr-xr-x 24 root root 592 2005-12-10 18:13 .
drwxr-xr-x 24 root root 592 2005-12-10 18:13 ..
drwxr-xr-x 2 root root 2.9K 2005-12-04 19:29 bin
drwxr-xr-x 3 root root 448 2005-12-04 19:49 boot
drwxr-xr-x 11 root root 16K 2005-12-09 15:52 dev
drwxr-xr-x 90 root root 7.8K 2005-12-09 15:52 etc
-rw-r--r-- 1 root root 40M 2005-12-06 14:03 etc.tar
drwxr-xr-x 2 root root 48 2005-12-10 18:13 foo
drwxr-xr-x 3 root root 72 2005-12-04 20:12 home
drwxr-xr-x 11 root root 4.1K 2005-12-05 02:19 lib
drwxr-xr-x 6 root root 192 2005-12-09 15:52 media
drwxr-xr-x 11 root root 280 2005-12-06 15:43 mnt
drwxr-xr-x 10 root root 264 2005-12-04 23:29 opt
dr-xr-xr-x 123 root root 0 2005-12-09 10:49 proc
drwx------ 14 root root 752 2005-12-10 18:10 root
drwxr-xr-x 3 root root 7.8K 2005-12-04 20:08 sbin
drwxr-xr-x 4 root root 96 2005-12-04 19:10 srv
drwxr-xr-x 2 root root 48 2005-09-09 05:59 subdomain
drwxr-xr-x 10 root root 0 2005-12-09 10:50 sys
drwxrwxrwt 25 root root 1.8K 2005-12-10 18:00 tmp
drwxr-xr-x 12 root root 344 2005-12-04 19:24 usr
drwxr-xr-x 14 root root 360 2005-12-04 19:14 var
drwxr-xr-x 5 root root 120 2005-12-06 15:38 windows
kimp4:/ # mkdir foo/a
kimp4:/ # ls -lha
total 40M
drwxr-xr-x 24 root root 592 2005-12-10 18:13 .
drwxr-xr-x 24 root root 592 2005-12-10 18:13 ..
drwxr-xr-x 2 root root 2.9K 2005-12-04 19:29 bin
drwxr-xr-x 3 root root 448 2005-12-04 19:49 boot
drwxr-xr-x 11 root root 16K 2005-12-09 15:52 dev
drwxr-xr-x 90 root root 7.8K 2005-12-09 15:52 etc
-rw-r--r-- 1 root root 40M 2005-12-06 14:03 etc.tar
drwxr-xr-x 3 root root 72 2005-12-10 18:13 foo
drwxr-xr-x 3 root root 72 2005-12-04 20:12 home
drwxr-xr-x 11 root root 4.1K 2005-12-05 02:19 lib
drwxr-xr-x 6 root root 192 2005-12-09 15:52 media
drwxr-xr-x 11 root root 280 2005-12-06 15:43 mnt
drwxr-xr-x 10 root root 264 2005-12-04 23:29 opt
dr-xr-xr-x 123 root root 0 2005-12-09 10:49 proc
drwx------ 14 root root 752 2005-12-10 18:10 root
drwxr-xr-x 3 root root 7.8K 2005-12-04 20:08 sbin
drwxr-xr-x 4 root root 96 2005-12-04 19:10 srv
drwxr-xr-x 2 root root 48 2005-09-09 05:59 subdomain
drwxr-xr-x 10 root root 0 2005-12-09 10:50 sys
drwxrwxrwt 25 root root 1.8K 2005-12-10 18:00 tmp
drwxr-xr-x 12 root root 344 2005-12-04 19:24 usr
drwxr-xr-x 14 root root 360 2005-12-04 19:14 var
drwxr-xr-x 5 root root 120 2005-12-06 15:38 windows
kimp4:/ # mkdir foo/b
kimp4:/ # ls -lha
total 40M
drwxr-xr-x 24 root root 592 2005-12-10 18:13 .
drwxr-xr-x 24 root root 592 2005-12-10 18:13 ..
drwxr-xr-x 2 root root 2.9K 2005-12-04 19:29 bin
drwxr-xr-x 3 root root 448 2005-12-04 19:49 boot
drwxr-xr-x 11 root root 16K 2005-12-09 15:52 dev
drwxr-xr-x 90 root root 7.8K 2005-12-09 15:52 etc
-rw-r--r-- 1 root root 40M 2005-12-06 14:03 etc.tar
drwxr-xr-x 4 root root 96 2005-12-10 18:14 foo
drwxr-xr-x 3 root root 72 2005-12-04 20:12 home
drwxr-xr-x 11 root root 4.1K 2005-12-05 02:19 lib
drwxr-xr-x 6 root root 192 2005-12-09 15:52 media
drwxr-xr-x 11 root root 280 2005-12-06 15:43 mnt
drwxr-xr-x 10 root root 264 2005-12-04 23:29 opt
dr-xr-xr-x 123 root root 0 2005-12-09 10:49 proc
drwx------ 14 root root 752 2005-12-10 18:10 root
drwxr-xr-x 3 root root 7.8K 2005-12-04 20:08 sbin
drwxr-xr-x 4 root root 96 2005-12-04 19:10 srv
drwxr-xr-x 2 root root 48 2005-09-09 05:59 subdomain
drwxr-xr-x 10 root root 0 2005-12-09 10:50 sys
drwxrwxrwt 25 root root 1.8K 2005-12-10 18:00 tmp
drwxr-xr-x 12 root root 344 2005-12-04 19:24 usr
drwxr-xr-x 14 root root 360 2005-12-04 19:14 var
drwxr-xr-x 5 root root 120 2005-12-06 15:38 windows
kimp4:/ # touch foo/c
kimp4:/ # ls -lha
total 40M
drwxr-xr-x 24 root root 592 2005-12-10 18:13 .
drwxr-xr-x 24 root root 592 2005-12-10 18:13 ..
drwxr-xr-x 2 root root 2.9K 2005-12-04 19:29 bin
drwxr-xr-x 3 root root 448 2005-12-04 19:49 boot
drwxr-xr-x 11 root root 16K 2005-12-09 15:52 dev
drwxr-xr-x 90 root root 7.8K 2005-12-09 15:52 etc
-rw-r--r-- 1 root root 40M 2005-12-06 14:03 etc.tar
drwxr-xr-x 4 root root 120 2005-12-10 18:14 foo
drwxr-xr-x 3 root root 72 2005-12-04 20:12 home
drwxr-xr-x 11 root root 4.1K 2005-12-05 02:19 lib
drwxr-xr-x 6 root root 192 2005-12-09 15:52 media
drwxr-xr-x 11 root root 280 2005-12-06 15:43 mnt
drwxr-xr-x 10 root root 264 2005-12-04 23:29 opt
dr-xr-xr-x 123 root root 0 2005-12-09 10:49 proc
drwx------ 14 root root 752 2005-12-10 18:10 root
drwxr-xr-x 3 root root 7.8K 2005-12-04 20:08 sbin
drwxr-xr-x 4 root root 96 2005-12-04 19:10 srv
drwxr-xr-x 2 root root 48 2005-09-09 05:59 subdomain
drwxr-xr-x 10 root root 0 2005-12-09 10:50 sys
drwxrwxrwt 25 root root 1.8K 2005-12-10 18:00 tmp
drwxr-xr-x 12 root root 344 2005-12-04 19:24 usr
drwxr-xr-x 14 root root 360 2005-12-04 19:14 var
drwxr-xr-x 5 root root 120 2005-12-06 15:38 windows
kimp4:/ # cd foo
kimp4:/foo # ls -lha
total 512
drwxr-xr-x 4 root root 120 2005-12-10 18:14 .
drwxr-xr-x 24 root root 592 2005-12-10 18:13 ..
drwxr-xr-x 2 root root 48 2005-12-10 18:13 a
drwxr-xr-x 2 root root 48 2005-12-10 18:14 b
-rw-r--r-- 1 root root 0 2005-12-10 18:14 c
kimp4:/foo # mv c reallylongfilenameiamgoingtojustrambleonkeepreadingyepyourebored
kimp4:/foo # ls -lha
total 512
drwxr-xr-x 4 root root 176 2005-12-10 18:15 .
drwxr-xr-x 24 root root 592 2005-12-10 18:13 ..
drwxr-xr-x 2 root root 48 2005-12-10 18:13 a
drwxr-xr-x 2 root root 48 2005-12-10 18:14 b
-rw-r--r-- 1 root root 0 2005-12-10 18:14 reallylongfilenameiamgoingtojustrambleonkeepreadingyepyourebored
kimp4:/foo # mv b folderisrenamedtoareallylongnamesoiwilljustkeepontypingtotakeupspaceseethesizeofdotnowitshuge
kimp4:/foo # ls -lha
total 512
drwxr-xr-x 4 root root 264 2005-12-10 18:25 .
drwxr-xr-x 24 root root 592 2005-12-10 18:13 ..
drwxr-xr-x 2 root root 48 2005-12-10 18:13 a
drwxr-xr-x 2 root root 48 2005-12-10 18:14 folderisrenamedtoareallylongnamesoiwilljustkeepontypingtotakeupspaceseethesizeofdotnowitshuge
-rw-r--r-- 1 root root 0 2005-12-10 18:14 reallylongfilenameiamgoingtojustrambleonkeepreadingyepyourebored
Now, without checking the source for ReiserFS or ls, one can make an educated guess that what is reported by the directory size is the size of the directory itself - that is, the size of the directory name and its contents' names and attributes.
Believe it or not, each directory entry you make takes up disk space - more on some filesystems than on others. Take FAT for example: if you create a new, empty directory that directory takes up space in the file allocation table. If the filename is longer than a FAT-16 8.3 filename, behind the scenes that directory is broken up into multiple directory entries (a FUGLY hack, I might add) and that all takes up at LEAST one cluster (anywhere from 512bytes to 32KB depending on formatting options). EXT2 works in a similar way - each directory takes up a cluster, plus there needs to be meta-data stored, that is, the directory's timestamp, permissions, etc. not to mention the mappings to the files that directory contains. Some other filesystems are a little more efficient and store this info in a b-tree structure (ReiserFS, XFS, and if I recall correctly UFS as well) which resmbles an RDBMS more closely than a conventional filesystem.
I hope this helped shed some light on things rather than confused you more. Filesystems are actually fairly complex structures.
|