Find the answer to your Linux question:
Results 1 to 6 of 6
Is Linux like Windows, in that when you delete a file, it really isn't deleted completely, or does it completely remove the file? Because I found out that for some ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Newbie
    Join Date
    May 2003
    Posts
    123

    Another file question about Linux


    Is Linux like Windows, in that when you delete a file, it really isn't deleted completely, or does it completely remove the file? Because I found out that for some reason, when running Windows, I would delete like 200 megs of files, and only end up with like 194 megs of free space.

  2. #2
    Linux Engineer
    Join Date
    Nov 2002
    Location
    Queens, NY
    Posts
    1,319
    Well, this depends on the situation. If you are using a desktop such as KDE, when you right click on a file, you get options. Here you can delete it to the trash bin or you can physically delete the file off the hard drive (in Windows, this is the same as holding shift while deleting a file).
    The command line is different than the desktop. When you delete a file with 'rm' it is physically deleted. If you don't like this, you can either create your own version of 'rm'.
    The best things in life are free.

  3. #3
    Linux Newbie
    Join Date
    May 2003
    Posts
    123
    So physically deleting it from the trash bin(i.e, emptying the trash bin) removes the entire file and any remnants of it permanently?

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    That depends on whose perspective you're using. For a normal user, that's true, but for a security expert it's not entirely true, in that removing a file only deletes references to the file. It doesn't actually zero out the underlying disk sectors, since it isn't normally necessary to do so; the next time they're being used, they're just overridden with new data as soon as a new file is created. This can be a security problem, though. With high-risk data, you want it to be really erased so that it cannot be retrieved later by an intruder, in case the sectors have not yet been reused. Therefore such files are normally manually "wiped" with zeroes or the like before deleted. That still leaves residual magnetic traces on the disk, though, so for really high-risk data, you always send the disk to an erasal company which makes sure no trace of the file is left.

    I guess this isn't your issue, though. It is true that once you delete a file (by eg. emptying the trash bin, removing it directly, unlinking it with rm, etc.), the entire disk space that was occupied by the file is completely reusable.

    There are some exceptions, though, that lies in the way a UNIX filesystem works.
    You know that in Windows, when a program uses a file, you cannot delete it, no matter what you do, right? That's not really the case in UNIX/Linux. In UNIX, a file name isn't directly linked to be the file itself, as it is an FAT. A file name is, precisely like it sounds like, just a name for a file. This means a couple of things:
    For one thing, you can have several names for a file. You can create another file name for a file using the "ln" command. Try it yourself: create a file named test, enter some text into it, the run "ln test test2". That will create yet another name for that file, called test2. Open test2, and edit the data. Save it, and then reopen test, and you will see that the data has changed. That's because both test and test2 refer to the same file. That also means that creating the second name "test2" doesn't use any more disk space, since there is still only one file. That also means that removing test will free no disk space, since the file is still left with the name test2. Only when the last name of a file is removed, the file itself is removed. You can see how many names a file has by running "ls -l". The number displayed before the user name is the number of names the file has. Though you'll see that most files only have one name, there are a few exceptions. This is also why the real term in UNIX for removing a file is to "unlink" the file, since the operation itself only removes a link to a file, and not necessarily the file itself.
    It also means that you're allowed to unlink a file that is currently in use, even though it will have no names left after you unlink it. That will cause the actual file to remain until the process that uses it either closes it or exits. You can try that by deleting an MP3 file while you're playing it. The MP3 player will go on playing it, since the file still remains in the system. It's only the name that's gone. Once the player is done and closes the file, the file will be removed and the disk space restored.

  6. #5
    Just Joined!
    Join Date
    Jun 2003
    Location
    Dunblane, Scotland
    Posts
    17
    Removing a file from trash removes it from the "list of files that you can access" it doesn't remove it from the disk. That's why Norton's can recover files on FAT filesystems so easily - as long as you haven't overwritten the file yet - because removing from the list isn't that devastating.

    Unix-like filesystems however use a different mechanism for addressing the files which makes file recovery more painful, but still possible after a file deletion. Again, this will only occur if you "remove it from the trash".

    Note that if you used the "rm" command at a Linux shell or a "del" command at a windows command prompt then it would bypass the trash and immediately delete the file. (As would shift-delete in Windows and KDE)

    Also, adding to Dolda has said, you can make links in NTFS - a link being effectively two or more directory entries to the same file. NTFS supports only hard links - links between files that exist in the same filesystem (i.e. on the same drive), whereas most (all?) Unix-like file systems support what are called soft links which can link a file between file systems.

  7. #6
    Just Joined!
    Join Date
    Jun 2003
    Location
    Helsinki, Finland
    Posts
    78
    If you want to permanently remove a file try shred.

    Quote Originally Posted by $ man shred
    shred - delete a file securely, first overwriting it to hide its contents
    If it's not include with your distro, grab it from GNU: http://www.gnu.org/software/fileutils/fileutils.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •