TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: why is it faster to delete files from a disc than to write them?

6 pointsby rickyconnollyover 12 years ago

4 comments

jacquesmover 12 years ago
Writing a file means that all the data has to pass trhough the file system, the io driver, the disk controller interface onto the disk with a certain maximum write speed. If the file is large then it will take a long time. The 'bookkeeping' to administer where the file goes is a very small portion compared to the data of the file in such cases.<p>When you delete the data you only update the bookkeeping, so that's much quicker.<p>If you were to erase the file then it would take <i>just</i> as long as writing it in the first place.
fencepostover 12 years ago
Inigo Montoya has it: "You keep using that word. I do not think it means what you think it means."<p>"Delete" in almost any computer context means "forget" not "erase." "Forget" the file metadata (generally the name, the link to the beginning of the chain of blocks on disk, etc.), "forget" the pointer to a block of memory, etc. Systems specifically designed for security may have additional provisions that turn those "forget" operations into "overwrite-and-forget," but in general simple forgetting is preferred for speed.
mooism2over 12 years ago
Because you're only removing the directory entry. The file contents are still on disk, it's just there's no easy way to know <i>where</i> on disk.
FlyingAvatarabout 12 years ago
Here's a very simplified example. Note that I am using some made up notation here: "." represents NULL charcaters, and the numbers would actually be stored in hexadecimal.<p>The contents of 48 byte disk with a 7 byte file allocation table (FAT):<p><pre><code> [................................................] FAT----DATA------------------------------------- </code></pre> Write a file named "blah" with contents "abcdefghi":<p><pre><code> [blah.90abcdefghi................................] FAT----DATA------------------------------------- </code></pre> Notice that the FAT area contains the filename, a "9" representing the length of the file, and a "0" indicating the spot in the data area where the file begins. In fact, the file system might choose the put the data somewhere else, and that's absolutely fine. For example:<p><pre><code> [blah.95.....abcdefghi...........................] FAT----DATA------------------------------------- </code></pre> Represents the exact same contents with the file stored at an offset of 5. So say I want to delete this file now. A typical file system would do something like this:<p><pre><code> [.lah.95.....abcdefghi...........................] FAT----DATA------------------------------------- </code></pre> It writes a single NULL byte to the file system to mark the filename as empty, and the file is gone. None of the rest of the data is cleaned up.