Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

From here 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
    
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
add comment

migrated from programmers.stackexchange.com Nov 8 '12 at 13:04

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

2 Answers

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. –  Vain Fellowman 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
add comment

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
2  
+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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.