Click to See Complete Forum and Search --> : du is inaccurate?
Red Lotus
09-20-2001, 04:57 PM
I've tried the du command (disk used) and it seems to be very inaccurate. It rounds greatly (1.5 kb is rounded to 4 kb). Here's the situation:
I created a text file in pico, with text like "This is a text file!" I saved it as 'example.txt' and used the du command to check how much space it occupied. The output was 4 KB (4096 bytes).
All my [short] text files that I created ended up as the same size, 4096 bytes. When I finally got suspicious of it, I opened up konqueror and checked the properties of the text file I created above. It said 1.5 KB!
What's up with that? Is the du command inaccurate? Is there a problem with my system alone? Is konqueror inaccurate? Do I need to update something (updatedb)? Is there a better command to use in order to check disk usage?
Feedback would be cool. Thanks. :D
element-x
09-20-2001, 05:01 PM
I don't know if this will make a difference at all, but have you tried...
du -h file
or
du -H file
See if those output the 'correct' file size?
Red Lotus
09-20-2001, 05:35 PM
du -h filename just makes the size "human readable" (ie. 4.0k). Thanks for the help though.
I took a closer look at the man page for du and found that du estimates file space usage. :( So is there another command I can use to check disk usage that is more accurate than du? I'd rather not start up konqueror each time I wanted to check for disk usage.
[ 20 September 2001: Message edited by: Red Lotus ]
Craig McPherson
09-20-2001, 06:49 PM
Block sizes.
File space is only allocated in blocks, so file sizes are always "rounded up" to the nearest block. If the block size of the filesystem is 4KB, 1-byte file will take up one block, 4KB. A 4076-byte file will take up one block, 4KB. A 4077-byte file will take up two blocks, 8KB. Even if a file doesn't completely fill a block, no other file can use that block, so it'll use up the full size of all the blocks it uses on disk.
Don't worry. The amount of "waste-age" doesn't add up to a significant amount. Ext2 filesystems can also use 1KB and 2KB block sizes, but 4KB is still pretty small. Other filesystems are much worse: ever see a FAT filesystem with +32KB blocks? Nasty, nasty.
[ 20 September 2001: Message edited by: Craig McPherson ]
MandK_10
09-20-2001, 06:52 PM
If you are familiar with windows you will have noticed a simular phenomenon there. Your disk is formated to 4k 'blocks'. Anything less than 4k (or 4096bytes) will show up as 4k. Just the nature of the beast.
There is nothing wrong with du.
[ 20 September 2001: Message edited by: MandK_10 ]
Red Lotus
09-20-2001, 08:05 PM
Thanks Craig and MandK_10! Craig, if I could rate you, you'd get 5 stars, but it's disabled, so...
Is it possible to change the block sizes by myself (Red Hat)? I just want to know. I'll keep it at 4 KB, because you said it was good, Craig.
Oh and, is there a man page on this?
Cheers! :)
klamath
09-21-2001, 12:00 AM
IIRC, it's 'man mke2fs', but there might be some info in 'man tune2fs'.
The trade-off WRT blocksize is performance versus disk space. With larger blocks, you have a smaller number of total blocks on the disk, which makes access faster. But it wastes (marginally) more space...
Considering the cost (very low) and size (very high) of IDE hard drives right now, I'd say don't worry about it.
Craig McPherson
09-21-2001, 06:35 AM
Right, you can specify the block size when you create the filesystem using mkfs (which is just a front-end to mke2fs). Tune2fs can be used to change some paramaters of an existing filesystem, but I don't think it can change the block size of an existing filesystem in a non-destructive manner.
Red Lotus
09-21-2001, 04:48 PM
I just have one more question. Is there a command that I can run from the terminal that will tell me the actual size of files, and not just the amount of blocks they take up?
Craig McPherson
09-21-2001, 04:55 PM
ls -l
isn't it just an idiosincracy(sp?) of ext2fs?