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...