When you overwrite a file, is the previous space freed?

by Jet Blue   Last Updated August 14, 2019 02:01 AM

Suppose you have a file called foo.txt that is 500 bytes in size. Suppose you create a new file that is 10 bytes in size and save it as foo.txt, thus overwriting the file. Does the OS (Windows and Linux) automatically ensure that the space no longer used (410 bytes) is freed?

In a second scenario, imagine you used the dd utility to create both the old and new foo.txt as described above. Will the OS automatically ensure that the space no longer used is freed?

I imagine that behind the scenes, all writes to a file use the same OS system calls and thus handling of overwrites will be consistent across programs...

Related Questions

Updated May 17, 2017 04:01 AM

Updated October 28, 2015 06:00 AM

Updated October 25, 2017 15:01 PM

Updated March 17, 2017 00:01 AM

Updated January 28, 2018 02:01 AM