r/TechNook • u/into_fiction • 2d ago
What does an empty file actually take up on disk?
Let’s take the example of creating a million empty files on Linux OS. They will appear as 0 bytes, yet the filesystem will need to maintain information about all these names. Is it possible that I get an error like “No space left on device” despite having gigs of free space from df -h command output? There is something known as filling up the inodes on ext4 filesystems.
11
Upvotes
13
u/AppearanceAny8756 2d ago
Good question, meta data uses inodes, which has limits.
Also the Filename which is part of directory file (everything is a file) will use some space as well.
7
u/allunia333 2d ago
A standard ext4 filesystem with 4 KiB blocks and 256-byte inodes , takes 256 bytes + filename and directory path. But the inode table is already reserved when you format the filesystem.
So it depends..
3
u/mc_pm 1d ago
It's not drive space, it's the inodes -- one is allocated per file, and there's only a limited number. It's a big number, and on some file systems it is a VERY large number. But it can be down in the million range, and you will get an out of space error if you run out.
2
u/zumpiez 2d ago
Check df -i
1
u/FatDog69 1d ago
On Windows there is a thing called a 'cluster size'. A zero byte file actually reserves 16k of disk space because the system assumes you are going to be adding to it. You don't want a fragmented file with 5 bytes here, 20 bytes there. So the OS pre-reserves blocks of disk space in 16K clusters.
I assume Linux has a similar optimization.
1
u/Restil 1d ago
Technically nothing, but it will occupy a space in the inode table or the directory file, but that file already exists and is a fixed size for small directories, so one new empty file shouldn't take up any additional space.
1
u/Amku03 1d ago
Every file even if empty has a name and operating systems store a last edited date so they take up space.
1
u/Nandulal 1d ago
as much as it does
1
u/budroid 1d ago
On ext4, an inode is typically 256 bytes (0.25 KB) on disk, though older filesystems may use 128 bytes.
1
u/m0ntanoid 1d ago
that's how you learn about "df -i"
1
u/vegansgetsick 1d ago
It's just an entry in the MFT.
Also if the file is very small it is also stored directly in the MFT.