In computers, why do some files, even if they are the same size, take longer to be moved or deleted than others?

506 views

I noticed this when I deleted a 2 GB video file on my laptop today, which took less than 5 seconds. But when I deleted a separate folder that was smaller than 2 GB, it took way longer to get deleted.

In: Technology

8 Answers

Anonymous 0 Comments

Most file systems don’t really erase data when a file is deleted. They just “forget” where that data was stored.

File systems use a small part of your disk to keep a kind of ledger of where every file is stored. “You want to load doge_picture_1.jpg? Go to sector 385018502820 and then read the next 8930 sectors.” This ledger also keeps track of which memory sectors are available to be written to, i.e. any parts that do not already contain file data.

When you delete a file, the file system just deletes the location information for that file from its ledger. It doesn’t actually go to those memory locations and manipulate the 1s and 0s that are stored there. These 1s and 0s can just hang out (each bit has to be either 0 or 1 anyway, it cannot be “empty”). Then when a new file is written, it might end up being written to some or all of these sectors, because the ledger shows that these sectors are now available.

This is why deleting files is pretty quick, and big files are deleted just as quickly as small files.

If the folder you deleted took longer than the video file, this is almost certainly because the folder contained a number of files or other folders inside of it. For each file, the file system had to make a change to its ledger. The more changes to the ledger, the longer it takes to do the whole deletion process. I could make a folder and fill it with a million empty text files, and it would take a long time to delete all of those, even though they take up almost no storage space.

(In addition to these ledger changes, the file system may also be performing additional “household” tasks for every file being deleted, e.g. checking that it’s not currently in use, that you have permission to delete it, etc. This all adds up to a bunch of overhead that has to be done for every file, regardless of its size.)

The fact that data isn’t actually being overwritten when you delete files means that it is often possible to retrieve the deleted data, using specialized software, as long as no new files have been written in those sectors. This can be a security risk if you really need to make sure that the data is completely gone. Permanently erasing a file also requires special software, which will overwrite the sectors occupied by that file with meaningless 0s and 1s (e.g. random or repeating sequences). Permanently erasing a 2 GB video like that would take quite a bit longer than erasing, say, a 5 MB picture.

You are viewing 1 out of 8 answers, click here to view all answers.