How are deleted files replaced by new ones?

179 views

Say if the internal storage of your phone were to fill up and you deleted something like a video or game, what is it actually doing to the file in order to take it off the storage and how are new files able to just replace it?

In: 3

8 Answers

Anonymous 0 Comments

I’m not in IT but I think when you delete a file it’s just a logical deletion, ie the data remains on the drive but it is marked as overwritable. So when you write in a new file, it’s written on top of the old one, making it unreadable. On most storage hardware you can actually recover deleted data without much difficulty, unless it has been overwritten by new files many times.

Edit:to elaborate.
Writing data on a medium is essentially using a magnet to mark tiny north/south areas on it (0s and 1s… Bits) You delete it, the magnetic head comes back to the same area of the medium and changes the magnetised areas again, overwriting the old file with a new one.

Anonymous 0 Comments

When you delete a file, you are not really removing it. You are removing the directory that points to the file. So the information is there, but the phone has that storage space marked as available, so a new file can be written on the space where the old one is.

(That is why deleted files can sometimes be recovered)

Anonymous 0 Comments

There’s a record in the filesystem saying what files exist and what blocks on the storage system contain the pieces of the file. When you delete something it just clears that record and marks the blocks available for new use. This means that the data is still technically there and could be read if you could re-discover the blocks and put them in the right order.

“Secure delete” goes in and zeroes out the bits first, to make sure the data actually no longer exists.

Anonymous 0 Comments

In a computer there is no such thing as nothing. Everything is 1’s and 0’s. You might thing that “0” represents nothing, but in terms of the information it carries, “0” is the same as “1”, so the computer needs a way of knowing whether some 1s and 0s in some place means something or not. To do this, it basically has a directory of what spots on the disk should be treated as actually having information (e.g. files) and spaces that shouldn’t (e.g. “empty” space).

When you write something new, your computer will look for somewhere in that “empty” space to put it, changing the 1’s and 0’s in that space to make the 1’s and 0’s of whatever it is you’re writing, it will then flag that spot as being a spot that contains information.

When you delete something, you might it should just overwrite what’s there with 0s. But, again. 0’s can be information, too. Rather it simply changes the directory to treat that space as empty so it can be overwritten. But until it is actually overwritten, the original data remains there.

Anonymous 0 Comments

Imagine a whiteboard in a classroom. A section with a box drawn around it that’s labeled “Do not erase” is a file that’s saved on disk. Anything outside of that is fair game to be erased and re-drawn.

When you delete a file on a hard drive, all you’re doing is erasing the box and “Do not erase” label. The contents of the box remain on the board until someone comes along and writes over them with something new.

When you want to write something new on the whiteboard, you just need to find an area that’s big enough, draw your box and “Do not erase” label, and then the space is yours to do what you please with it.

Anonymous 0 Comments

Your computer’s storage is simply a vast sea of 1s and 0s that any program can use.

When one of them wants to create a file, it asks the operating system to allocate a portion of the hard disk to them. The OS then stores an entry saying “file A.txt is using bytes 1000 to 1500”. B.txt might be using bytes 2050 to 5000, and so on. New files simply find an unused range and “claim” it.

When a file is deleted, the operating system just has to delete the entry in its index that it made for that file. The bytes themselves are left untouched. In the future, any other file looking for space can claim that range for itself and overwrite the data that was previously there.

This is how file recovery software is able to work. After the file is “deleted”, the software can still read the bytes on the disk and, as long as no other file has been written to the same location, recreate the original one.

Anonymous 0 Comments

Other answers here are pretty good, but I’ll add my two cents in:

At the simplest level, your computer keeps an index of all the files on your drive, a bit like a phone book. It stores where the file starts on the disk and where it ends. When you delete a file, your computer looks up the file in the index and crosses it out. It’s not actually deleted, but in the index, it’s as good as gone.

Then when your computer wants to save another file, it looks up the index, sees that a particular spot is free, and just writes over it, overwriting the old file in the process.

In reality, the index doesn’t store info about a whole file, but rather parts of a file. Say for example you have a file that is five blocks long. You delete it, then you want to save a file that is six blocks long in there, but you can’t do it. So instead you save 5 blocks in there, then 1 block elsewhere, and just mark in the index “file A has 5 blocks here, and 1 block there”.

After doing this for a while, your computer will slow down because what if you have a file that is 100 blocks long, but it’s split up into 37 parts, with some at the start and some at the end of the disk? You’d have to read the drive at one point, move the needle (if using an older mechanical drive), read again, move again, and so on.

So people came up with the idea of defragmentation. When your computer has some down time, it’ll shift parts of files around on disk and update the index, so if you want to read a file that is 100 blocks in size, you can just start at the beginning, read 100 blocks, and there’s your whole file. The computer don’t need to hunt around on the disk to find it, because your computer has done its very best to ensure that files are all stacked neatly in a logical order. It’ll do the same with folders, so instead of a whole file being at point A on the disk, and the next file in the folder being at point Z on the disk, it’ll rearrange the files and the index so that the first file in the folder will be at point A, and the next file in the folder will be at point B, and so on.

Anonymous 0 Comments

Digital storage is similar to locker room with a manager.

When you save a file, the manager will dissemble your file. He will select some free lockers, take the old things out and put your things in, and mark those lockers. When you delete a file, the manager will remove the mark from those lockers so they can be used again.