Timeline for What does the "size in 512-byte blocks" mean?
Current License: CC BY-SA 3.0
8 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| May 18, 2017 at 21:38 | comment | added | user4556274 | @mbigras Because the file requires more than 0 but less than 4097 bytes, OS X allocates one disk block of 4096 bytes. The fact that the -ls display defaults to a blocksize of 512 bytes is historical, and forces the display for your disk to be in multiples of 8. For comparison, if you execute ls -s, you should see the same number of mythical 512-byte blocks, but if you correct the system's view of disk block size with BLOCKSIZE=4096 ls -s you should get the actual number of disk blocks. I don't know why utilities use historic values rather than querying the hardware for actual blocksiz | |
| May 18, 2017 at 21:04 | comment | added | mbigras | So because the file contains 2 bytes OS X allocates 4096 bytes for that file, which is 512*8 and therefore there are 8 512-byte blocks allocated for that file? | |
| May 18, 2017 at 20:37 | comment | added | user4556274 | @mbigras, because the actual block size on your disk is 4096 bytes, not 512. If you are using OS X, issue diskutil info / | grep "Block Size" | |
| May 18, 2017 at 20:24 | comment | added | mbigras | So why is it 8 512-byte blocks instead of 1 512-block? @ilkkachu good catch cat is telling us! Because cat some_file gives h% which means there is no newline on OS X | |
| May 18, 2017 at 20:13 | history | edited | user4556274 | CC BY-SA 3.0 | deleted 9 characters in body |
| May 18, 2017 at 20:10 | comment | added | ilkkachu | We know the file contains a newline too, since that's what cat printed! | |
| May 18, 2017 at 19:53 | comment | added | cutrightjm | To further this answer, you can use the -n switch with echo to "not output the trailing newline". With echo -n "h" > some_file you will get a size of 1. | |
| May 18, 2017 at 19:49 | history | answered | user4556274 | CC BY-SA 3.0 |