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*

5
  • 3
    As Linux supports sparse files on most file systems, the behaviour is well-defined and the disk driver can really free disk space. I have tested it for ext3 and ext4, and it works like Stephane wrote. Commented Mar 20, 2013 at 10:14
  • 1
    What makes you say that truncating a file will not reclaim preallocated blocks? Truncating is meant to deallocate data, I don't thing there's any ambiguity with that. Commented Mar 20, 2013 at 11:22
  • 1
    The file system may keep the blocks allocated to save time later (especially if the file still remains open), especially when it was big enough before truncating. At least that's what XFS seems to be doing. Commented Mar 20, 2013 at 12:53
  • 1
    Thank you Peter. I am glad that you address the "why" in this post. Commented Mar 21, 2013 at 6:09
  • 3
    As far as I can tell, truncating open files does reclaim space on XFS as well. Tested with both normal file and file allocated with fallocate on Linux 4.9. Can you please clarify under what filesystem and condition truncating a file does not reclaim space? Commented May 3, 2017 at 11:52