Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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).
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"
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.