LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-10-2005, 04:53 PM   #1
Milosevic
LQ Newbie
 
Registered: Nov 2005
Posts: 19

Rep: Reputation: 0
directories size is always 4K


Why is the directories size always 4K ?

milosevic@slackws:~$ ls -ldh /
drwx--x--x 25 milosevic users 4.0K 2005-12-10 19:47 //

I mean, shouldn't it be the sum of the sizes of the files that the dir contains? Or does it have anyhing to do with the inode's size?

Cya fellas.
 
Old 12-10-2005, 05:18 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
I can't tell you why your root directory is 4K in size,
but the fact that it's not owned by root:root is a worry.

Who set-up that box with those incredibly stupid ownerships?



Cheers,
Tink
 
Old 12-10-2005, 05:26 PM   #3
Milosevic
LQ Newbie
 
Registered: Nov 2005
Posts: 19

Original Poster
Rep: Reputation: 0
hm... sorry... actually the thing is like this:

milosevic@slackws:~$ ls -lhd /
drwxr-xr-x 19 root root 4.0K 2005-12-09 15:22 //
 
Old 12-10-2005, 05:35 PM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
it's the block size of the filesystem. the size of a directory and the size of all files within it are a totally different thing.
 
Old 12-10-2005, 05:43 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Hmmm ... nice attempt of an explanation, but I don't think
it's correct. On 4 different machines here I get four different
sizes, and they're all under 1K (616,624,704,512) ... so the
"human-readable" didn't quite mess up the results.


Cheers,
Tink
 
Old 12-10-2005, 06:09 PM   #6
KimVette
Senior Member
 
Registered: Dec 2004
Location: Lee, NH
Distribution: OpenSUSE, CentOS, RHEL
Posts: 1,794

Rep: Reputation: 46
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:

Code:
hostname:/# du -h
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.

Last edited by KimVette; 12-10-2005 at 06:13 PM.
 
Old 12-10-2005, 06:52 PM   #7
Milosevic
LQ Newbie
 
Registered: Nov 2005
Posts: 19

Original Poster
Rep: Reputation: 0
file size.

Code:
milosevic@slackws:~$ echo a > file.txt
milosevic@slackws:~$ ls -l file.txt 
-rw-r--r--  1 milosevic users 2 2005-12-10 21:49 file.txt
If every file takes up at least one cluster of the file system, why the hack the "file.txt" only takes one byte? (i believe the cluster size here is 4k).

Cheers, Milosevic.
 
Old 12-10-2005, 06:59 PM   #8
KimVette
Senior Member
 
Registered: Dec 2004
Location: Lee, NH
Distribution: OpenSUSE, CentOS, RHEL
Posts: 1,794

Rep: Reputation: 46
Well some filesystems (ReiserFS) are "zero-slack" which means that if a file is 1 byte, it takes one byte (well, plus a couple of delimiters). Others (ext2, uncompressed NTFS, FAT) require that whether file is 1 byte or 511 bytes on a filesystem partitioned with 512-byte clusters, that the file be allocated a minimum of one FULL cluster - that is, 512 bytes. The wasted space is usually referred to as "slack"

Why does LS report the file size as one byte? Because the file's contents is one byte. You're confusing file size with disk usage. If you dual boot Windows, here's a quick demonstration:

On an uncompressed FAT or NTFS partition, create an uncompressed file which is say, *picks an abitrary number* 42 bytes. Open up that file's properties, and in the properties tab, check out two entries:

* file size
* space used on disk (I forgot exactly what the two fields are called)

The numbers will be different. One will show the size of the file's contents, and the other will show how much space on the disk is allocated to it. The difference between the two is allocated but unusable space called "slack"
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
hd partition size/directories ziggie216 Linux - General 3 11-10-2005 12:58 PM
Searching multiple directories and sub directories for a file jeep99899 Linux - Newbie 2 10-13-2005 01:23 PM
cannot re-enable konqueror automatic updating of directories (file-size) Emmanuel_uk Linux - Newbie 3 06-28-2005 03:01 AM
check the used size of the directories ust Linux - Software 2 02-02-2005 07:47 AM
list size of directory and all directories it contains? ubien Linux - General 2 01-11-2003 11:59 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration