13

I have a simple question.

When we create a file, let's say "abc.txt" and leave it blank.
The OS will show that the file is 0 bytes size and takes 0 bytes on disk.

If we save 100 of these 0 bytes file into a folder, the OS will also say that the folder's total size is 0 bytes.

This may sound logical because there is nothing in the file. But should not these files take at least a few bytes in the storage device?

After all, we save it somewhere and named it something. Shouldn't the file's name and possibly some other headers at least takes up some space?

keatch
  • 2,187
  • 2
  • 17
  • 22
Karl
  • 5,613
  • 13
  • 73
  • 107

4 Answers4

10

No, they still occupy a few bytes on the file system. Otherwise I would implement a magic filesystem that stored everything encoded in the filenames on empty files.


Technically it boils down to a matter of definition though. Either the "size of a file" refers to the size of the content of the file, or it refers to the "difference" it makes in terms of free bytes on the underlying file system (that is, size of content (rounded up to the closest block- or cluster-size) + bytes used for it's inode).

aioobe
  • 413,195
  • 112
  • 811
  • 826
  • So basically, the OS hides all these information away from us? – Karl Feb 10 '11 at 08:57
  • Well, it depends on how you see it. If you have a [FAT](http://en.wikipedia.org/wiki/File_Allocation_Table) or similar, it may be a matter of definition, whether or not the filename, path and so on, is part of the file itself. – aioobe Feb 10 '11 at 08:59
3

These details are stored into what is known as File Allocation Table (talking in Windows FAT context) traditionally. They are created when we format the hard drive. Some predefined space is allocated for it. I don't think the size of it changes.

For example, you format a 100 GB hard drive, only 90+ GB is available for you to use. Other space is used by the file system to manage/remember each file/folder that is saved on the hard drive and where it is saved.

decyclone
  • 30,394
  • 6
  • 63
  • 80
3

The answer to this question is file-system dependent.

For example, on NTFS an empty file takes up a cluster, and a cluster has a size that depends on your hard disk size.

Here you can read some common cluster size for Windows' file systems.

Simone
  • 11,655
  • 1
  • 30
  • 43
2

The fact that they are present on disk means that a record has been created for them, which of course requires some amount of memory. The 0 bytes simply corresponds to the logical size of the file rounded to the granularity displayed in the UI, but even then it likely contains a file header which will depend on the file format.

Ed S.
  • 122,712
  • 22
  • 185
  • 265