Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • 1
    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. Commented May 18, 2017 at 19:53
  • 1
    We know the file contains a newline too, since that's what cat printed! Commented May 18, 2017 at 20:10
  • 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 Commented May 18, 2017 at 20:24
  • @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" Commented May 18, 2017 at 20:37
  • 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? Commented May 18, 2017 at 21:04