Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

From an article on file recovery I read, that when a file is deleted on your computer, only a pointer to the file is deleted and the space occupied by the file is marked as free to use. Is the only reason for this to recover "deleted" files or are there any other reasons why the space occupied isn't actually deleted (bits set to zero)?

share|improve this question

migrated from Nov 8 '12 at 13:04

This question came from our site for professional programmers interested in conceptual questions about software development.

Consider erasing the blocks used by a file on slow media. FAT was initially designed for floppy disks, and even floppies became faster as technology progressed. The ability to recover deleted files is largely a side effect of the decision to not overwrite the data, not the other way around. More modern file systems (particularly those with copy-on-write technology: btrfs, zfs, ...) have other considerations (by the time you delete the file, you might not even have a record of where each copy has been stored historically, and you certainly don't want to double every write if you don't have to). – Michael Kjörling Nov 8 '12 at 13:35
up vote 20 down vote accepted

The reason to prefer unlinking instead of zeroing a file is performance. It's far easier to simply zero a variable in the filesystem data structre rather than start overwriting an entire file. In modern filesystems unlinking the file takes a constant amount of time regardless of file size, whereas the time spent overwriting a file is proportional to file size.

share|improve this answer
+1 For the last sentence. – Bruno Schäpper Nov 8 '12 at 12:11
"Unlinking the file takes a constant amount of time regardless of file size" - whether that is true depends on the data structures used to manage free space. Many older filesystems use a block bitmap, where freeing space takes time proportional to the file size. – Michael Borgwardt Nov 8 '12 at 12:21
@MichaelBorgwardt Thanks, modified the answer for clarity. – zxcdw Nov 8 '12 at 12:36
Couldn't have said it better. – octopusgrabbus Nov 8 '12 at 18:12

Because it would take much more time, and is not necessary unless you want to make the recovery of deleted files impossible, which is rarely the case.

share|improve this answer
+1 for "much more time". The file system wasn't designed with zeroing out data as a requirement, but it was designed to be as fast as possible. – Scott Whitlock Nov 8 '12 at 12:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .