Slashdot Mirror


Undelete In Linux

Manuel Arriaga writes "[To the editors: I am not a professional programmer, nor will I ever be one. My income does not depend on my computing/programming skills, and hopefully it never will. So promoting free software I wrote does not help me in any financial way, no matter how indirect. libtrash is free software (GPL2), and I distribute it for free from my website. I have nothing to gain from the increased exposure, except for knowing that I am helping others. And I know slashdot isn't freshmeat... With that out of the way:] I have seen this topic discussed in the LKML multiple times by now, and many more people asking in the newsgroups why "I can't recover my deleted file on GNU/Linux". Here is my answer to that question. libtrash gives Linux a real "trash can". And it has been doing so (with varying degrees of stability) for more than one year now. If you consider it appropriate, make this information public on slashdot."

34 of 565 comments (clear)

  1. Recycle Bins - don't you just hate them? by fruey · · Score: 4, Insightful
    Reasons you don't need a recycle bin:
    • Because rm doesn't take -f by default
    • Because delete means delete, not put somewhere until I decide I really don't need it
    • Because you're a Linux user and have a clue
    • Because you're sick of people who restore files from the recycle bin because they think it's some kind of temporary folder
    • Because you don't want anything to do with "recycling", you have /dev/null and you put everything there
    • Because you have a poor machine with less than 4Gb of disk and you need all the space you can get

    I can't believe how many Windows users get caught out when they dual boot my machine into Windows (have to have it for the office because others use my workstation) and find I have disabled the Recycle bin. Haha, more fool them.

    Disclaimer: take with a pinch of salt. If you have sodium issues, take with a pinch of Lo-Salt instead.

    --
    Conversion Rate Optimisation French / English consultant
    1. Re:Recycle Bins - don't you just hate them? by yatest5 · · Score: 2, Insightful

      Yes, you're right. And all the people who contributed to this discussion (http://ask.slashdot.org/article.pl?sid=02/09/29/0 2 7256 ) are wrong.

      Nice attitude.

      --
      • Mod parent up! [a] by Anonymous Coward (Score:5) Thurs, June 31, @13:37
    2. Re:Recycle Bins - don't you just hate them? by Coplan · · Score: 5, Insightful
      A friend of mine once told me that he would start using linux when they had a trash can type of thing. His reasoning was that he liked to make sure that his files weren't needed. He'd delete something, then wait about a week or so of regular computer usage before removing it from the "recyle bin". For him, this type of tool is very useful.

      If we want joe-user to use linux, we need silly stuff like this.

      For you and I (and those in the know), we know damn well that you can delete a JPEG without it affecting anything. And if we're in doubt about a file, we know to move it somewhere temporarily. If something breaks, move it back. It's not all that often that you'll be deleting system files (and even then, its usually configuration files).

      Anyhow, I guess the reality is that a tool like this only needs to be useful to someone. If it is useful to a couple of people, then its worthy of its existence. It's not like it is a default application. Don't use it if you don't want it. That's the beauty of the Open Source world...you can do what you want.

    3. Re:Recycle Bins - don't you just hate them? by Transient0 · · Score: 5, Insightful

      It is nice to be able to have the cheap sense of superiority that comes with not needing something that someone else needs. Of your reasons, only one is valid that I see:

      >Because you have a poor machine with less than 4Gb of disk and you need all the space you can get

      But still, no matter how long you've been a linux user it's still possible to accidently type "rm core *" rather than "rm core*" and not catch it until half a second after you hit enter and realize that you have irrecoverably destroyed your project(you didn't really want to punish it for segfaulting).

    4. Re:Recycle Bins - don't you just hate them? by wilhelm · · Score: 2, Insightful

      Aliases like that are a good way to screw yourself. If you depend on that -i alias, what happens when you move to a system (or su to a user) which doesn't have that same alias? Pain, most likely.

      For some reason, Redhat systems do just the opposite of what you describe - root gets -i (on rm, cp, and mv), and everybody else doesn't. One of the first things I do on those systems is remove those aliases from root's bashrc, just to forestall any trouble.

    5. Re:Recycle Bins - don't you just hate them? by TheTomcat · · Score: 3, Insightful

      But still, no matter how long you've been a linux user it's still possible to accidently type "rm core *" rather than "rm core*" and not catch it until half a second after you hit enter

      I once typed `rm -r logs/old /` instead of `rm -r logs/old/`

      ... as root...

      ... on a production machine ...

      ... that didn't yet have the backup-unit installed (by our colo -- their problem)...

      that was a sucky weekend. (-:

      S

    6. Re:Recycle Bins - don't you just hate them? by thomas.galvin · · Score: 2, Insightful

      I've said it before, I'll say it again: ctrl-s saved, ctrl-d deletes. They should not be that close together.

    7. Re:Recycle Bins - don't you just hate them? by mcg1969 · · Score: 3, Insightful

      Once on an old Ultrix machine I wanted to delete some dot-files, including a subdirectory that started with a dot. So, as root, I typed

      rm -rf .*

      The problem with that was that '.*' included '..' ... so eventually it ascended into the parent directory, and began deleting every file and directory there. That was particularly unfortunate because the parent directory was the root directory!

      Before I realized what it was doing it had wiped out /bin and /etc. And this was our department's file server, so yes I had a sucky weekend too... I couldn't even give the machine a proper shutdown because I'd managed to wipe out that command!

  2. So everyone is perfect? by GreyyGuy · · Score: 5, Insightful

    I don't understand why there are so many people saying this is bad or implying that people who use Linux don't need it because they are so good. I must have missed the evolutionary step that made all Linux users so perfect that they never make mistakes. That is all the Recycle Bin is.

    Sure, some people use it as temporary folder, but so what? There will always be people who use things other then the way they are intended. If it works for them, so what? If it is so painful for you to contemplate, don't look at it.

    1. Re:So everyone is perfect? by Znork · · Score: 4, Insightful

      Because a lot of us _mean_ rm when we type rm. Otherwise we would have used mv. Or used Nautilus or some other filemanager that by default puts stuff in the trashcan.

      rm means 'remove'. Not 'move to trash'. Think of it as the 'empty trashcan' command. Would you like a trashcan that moves things to yet another trashcan when you empty it?

      If you're uncertain about wether or not to remove something dont use rm. You're entirely free to rm /bin/rm if you dont want to use it. Or even mv /bin/rm /tmp if you're uncertain about wether or not to remove it permanently.

      And if you, despite knowing that rm means 'remove', make a mistake, just restore from your backups.

    2. Re:So everyone is perfect? by mr_z_beeblebrox · · Score: 2, Insightful

      And how long before virus writers realize this and start explicitly infecting the /tmp folder?

      Most undelete folders with cots products have their own default settings which are very weak that is why they are targeted. If they can target /tmp that is the admins fault, executable code does not belong in /tmp at least not with the intention of it being run.

  3. I know you're kidding, but.... by FreeLinux · · Score: 4, Insightful

    [x] Trashcan support
    [X] Easy to use Windowing system - KDE
    [X] Standard software install system - LSB, Red Hat, Mandrake, Suse
    [X] Easy to use Windows filesharing - KDE, Samba
    [ ] Easy support for video files and DVD - No answer
    [X] Desktop company support - Red Hat, The Kompany

    1. Re:I know you're kidding, but.... by Josuah · · Score: 4, Insightful

      [X] Easy to use Windowing system - KDE

      Um, KDE is really nice and my windowing system/manager of choice under Linux. But it's really not so "easy to use" "all the time" to the degree that Windows and Mac OS are.

      [X] Standard software install system - LSB, Red Hat, Mandrake, Suse

      By listing four things here, you've gone right ahead and said that the software install system is _not_ standard. There is a very different user experience for each distribution's install, enough to make the average user think he is installing a different OS for each one. I know my mom thinks Red Hat is an OS.

      [X] Easy to use Windows filesharing - KDE, Samba

      I can't say Samba is easy to use Windows filesharing. Easy to use Windows filesharing is clicking on a button that says share files and seeing that folder show up in Network Neighborhood. It's not SWAT.

    2. Re:I know you're kidding, but.... by iapetus · · Score: 3, Insightful
      By listing four things here, you've gone right ahead and said that the software install system is _not_ standard.

      Then what OS would you recommend that *does* have a standard software installation mechanism? Windows certainly doesn't count - I've used three entirely different installer applications just today...

      --
      ++ Say to Elrond "Hello.".
      Elrond says "No.". Elrond gives you some lunch.
    3. Re:I know you're kidding, but.... by RealAlaskan · · Score: 2, Insightful
      Um, KDE is really nice and my windowing system/manager of choice under Linux. But it's really not so "easy to use" "all the time" to the degree that Windows and Mac OS are.

      Since you mention Mac, you probably don't think ``easy to use'' means ``just like MSWindows''. What does ``easy to use'' mean to you?

      My four-year-old has no more problems with KDE than she does with MSWin. Both kids manage to screw up MSWindows periodically. They haven't managed to get Linux (currently RH7.3) screwed up enough to need help for quite a while. For me, Linux is easier to use as a kid's toy than is MSWindows. If it only ran Reader Rabbit!

      My wife couldn't tell which OS the kids were running until I taught her to look for the big K versus Start. She knows that our box is always running Linux, and hasn't had any problem browsing the web and reading email. I don't have to worry about her opening the viruses our goofy friends send her, either (knock on wood). If I trained her to su to root, and type ``apt-get update;apt-get -u upgrade'', she could do the system administration, too. It's not that easy on Windows.

      A friend just got a WinXP computer (on purpose, yet!). He's having terrible problems getting it into a usable state. If his mind didn't go blank at the mere thought of understanding his machine, I'd set him up with Debian, since I suspect that KDE would be easier for him to do his thing with. He liked Knoppix, but the thought that it's non-MS worried him.

      Linux presents a lot of little difficulties, but so does MSWin. The difference is that if you know what you are doing, you can fix the problems with Linux. Presetup Linux isn't ready for the desktop yet, but neither is presetup Windows.

  4. README? by brunes69 · · Score: 3, Insightful

    Why is there no README or any other info on your site about this thing? I want to know how it works and how it is different from alias rm='mv ~/.trash', or the KDE trashcan, before I download it. Man I hate sites like this that expect you do download the package, then untar it, just to read a README file. How hard is it to throw it on your website with a link?

  5. metacommentary! by fraxas · · Score: 2, Insightful

    Please ignore the idiots above -- the l1nux-l337 are always a pain in the butt about usability issues. As a response to the ask-slashdot rfe from last week, this works really well.

    As a point of note, those of you complaining about the disclaimer in the article should realize that, if the disclaimer hadn't been there, you would be complaining about how "/. isn't an advertising service, you Window$ Idiot!!111!11!!!11!!"

    Sheesh.

  6. Not a solution by cpt+kangarooski · · Score: 5, Insightful

    While a trash can is nice to have, this doesn't fundementally address the issue of retrivability of accidently deleted information. That is, there is still going to be a step where information is going to be classed as unretrivable even when it COULD be retrieved. (i.e. when the trash is emptied)

    Clearly users appear to want to be able to correct mistakes that they've made -- perhaps even those that were not immediately apparent as being mistakes at the time -- for as long as possible. A trash is a step in that direction, but simply does not go far enough.

    My proposal is this: 1st it should be recognized that when you delete a file, you're really only marking the space where that file was as being available to be overwritten by more data. The original data is there, but what it consisted of, and where it was, are lost.

    So, let's keep that information in a log so that we can in a very real sense undelete anything that has not yet been overwritten. This log is not especially large, and with modern drive sizes is not a serious concern.

    Then, let's order the overwriting process to favor the maximum preservation of data. So for example this might result in new writes being done to the areas of the oldest deleted files first. Important files might be considered to be worth preserving longer, with importance dervived from various factors such as number of accesses, etc. prior to deletion. There's definately work for some user testing here to determine the optimal method. That's okay.

    If fragmentation is a worry, (bear in mind most people have never heard of it) then defragging software could take into consideration the undelete log and continue to preserve as much of the deleted data as possible when it shifts information around on the disk.

    In any event, the objective is to forestall the day when you have to tell a user who wants to undelete a file for as long as possible. Not longer, which the trash solution does, but AS LONG AS POSSIBLE.

    --
    -- This and all my posts are in the public domain. I am a lawyer. I am not your lawyer, and this is not legal advice.
  7. What we need now is by dfgdfgdfg · · Score: 2, Insightful

    What we need now is the Gnome (or KDE) panel set LD_PRELOAD so that all application can use libtrash.

    --
    -- 1.e4 c6 2.d4 d5 3.Sc3 de4: 4.Se4: Sd7 5.Sg5 Sgf6 6.Ld3 e6 7.S1f3 h6 8.Se6:
  8. False sense of security by Myshkin · · Score: 5, Insightful

    So, what happens if you send something like ld.so, or your kernel into the recycling bin? Experimenting by randomly moving stuff you don't understand is never a good idea. Just sending it to some sort of recycling bin just gives folks a false sense of security and could lead them to completely hosing their entire install.

  9. Re:What a drag by cpt+kangarooski · · Score: 3, Insightful

    So you must never wear a seat belt either because you've never been in a fatal car accident.

    Moron.

    --
    -- This and all my posts are in the public domain. I am a lawyer. I am not your lawyer, and this is not legal advice.
  10. Its called backup by jhines · · Score: 3, Insightful

    Don't delete anything, till it has been backed up. You do back up your data, right?

  11. Linux needs this at the filesystem level ... NOW by krray · · Score: 4, Insightful

    I've been a rabid Linux user from the early days. Today Linux handles DNS, Email, and Web services on my networks...it does NOT handle file access for JUST THIS REASON (lack of undelete).

    I'm not worried about *me*. When I delete something I fine with it being completely gone. What about completely clueless network users though? Being the MIS/IT MGR for where I work having access to "salvage" on the Novell Netware file servers is a wonderful tool for users mistakes.

    Classic example: last week one user created a Excel spreadsheet to be completed by another user. The second user opened the spreadsheet from Word, modified it, and saved it (as a .XLS file). Excel says it's corrupt (it's a Word document now).

    Getting the inserted table [spreadsheet] from Word back into Excel was next to impossible. Crappy Microsoft programming as usual -- and clueless users to boot. Easiet solution was to salvage the original spreadsheet and instruct user what NOT to do and re-enter the damn data PROPERLY this time.

    Linux would have left me high and dry. Well, not really, but having to go back to tape backups to simply salvage one file is a pain in the butt.

    I guess Linux will be nothing more than a niche product/market if "gurus" keep their attitudes posted here. Wake up and pay attention to corporate users and admins wants/needs. Telling me I'm clueless and wrong won't gain more market share (well, for Linux at least) -- I've recently bought another Netware license to cover just this issue for another remote office.

  12. Re:Here's a Handy Hint by yelligsc · · Score: 3, Insightful

    Once upon a time I wanted to delete a couple stray mp3s I had in my home directory, so I issued the following command:

    rm *.mp3

    Or so I thought. I had actually accidently told my linux install to do the following in my ~/

    rm * .mp3

    If you cannot tell, there is a " " between "*" and "." As you can imagine this has a very undesired effect, even though I saw it quickly after hitting enter and mashed the ^C as fast as I could.

    Undelete would have been useful then. Yes, its a dumb mistake.. but things happen!

    Scott.

  13. Real-life Analogy by LPetrazickis · · Score: 2, Insightful

    Often, when I clean out my papers, binders, and whatnot, I end up throwing out stuff that I do need. Being able to root through the trash and retrieve it five minutes later when I come to my senses is very convenient.

    Yeah, yeah. I am not leet.:)

    --
    Is this a sigs-optional kind of place? 'Cause I am totally down with that if you know what I mean.
  14. Re:Here's a Handy Hint by jxs2151 · · Score: 3, Insightful
    Don't Delete Shit You Want to Keep!


    Is it that hard?


    And this my friends is the attitude keeping Linux from wider acceptance......

  15. No, I don't. by Rui+del-Negro · · Score: 5, Insightful

    Technically, you can use a pint mug to drink champagne. But most people prefer to use a champagne glass or a flute.

    Personally, I prefer to simply hit "delete" to move files to a preset temporary directory (which can also remember where those files originally were, and restore them with a couple of clicks) than to have to manually drag them to a directory I created.

    If this kind of "commodity" seems pointless to you, then you probably program by writing machine code with a text editor. ;-)

    RMN
    ~~~

  16. Re:What a drag by crimoid · · Score: 3, Insightful

    >> tell the world why linux needs an undelete

    Because the world does not consist of perfect people. Most people will f*ck up from time to time and hose something that they didn't want. While I won't be installing this on any of my systems I'm sure that some of the more consumer-oriented distros might want to add this type of functionality to their products.

    That being said, I could see how something like this could be beneficial to many people, so having it as an option is a Good Thing. No one is forced to use it, but it's there for those who do.

  17. Quit running as root you donkey by Gimpin · · Score: 1, Insightful

    There is no need for a trashcan...quite running as a priveleged user. Pay attention to what you are doing, and if you manage 'rm -rd /*', you have once again proven evolution has skipped you.

    --
    "Simon Says, Fuck You" - George Carlin
  18. Re:Complacency by Reziac · · Score: 3, Insightful

    Actually, I've found it's the other way around. If average users know that every mistake is fatal, they become afraid of making ANY mistakes, and that's when you discover a HD completely filled up with garbage that they didn't dare dispose of.

    --
    ~REZ~ #43301. Who'd fake being me anyway?
  19. Fragmentation. by 0x0d0a · · Score: 3, Insightful

    This isn't an issue of "lighting fast". The proposed solution, at least without serious modification, would massively fragment the hard drive. The only reason you don't *care* about fragmentation is because you enjoy the pleasant fruits of the fragmentation-resistant ext2, so you don't realize how bad fragmentation can get. The proposed system would fragment the filesystem so badly that a well-used FAT32 system would look contiguous as hell.

    You could make a usable system that's somewhat similar...it could shift files around and use, say, a third of the free space for old files.

    1. Re:Fragmentation. by 0x0d0a · · Score: 3, Insightful

      The "twin file tables system", as far as I can tell, used a minimal-overwite algorithm -- overwrite absolutely no more files than is necessary.

      That's expensive. That *will* fragment files badly.

      Now, say you propose defragging on the fly. If you have a fragmented series of files, you have to defrag on the fly while doing writes. Plus, your disk is essentially always 100% full, *and* to make this a sane system, all of your operations have to be atomic. This is a worst-case scenerio for defragmentation. If you've ever tried defragging a full FAT32 filesystem, you know what I'm talking about.

      So what *used* to be slapping a chunk of data down onto a disk now becomes a number of moves of data to defragment files, plus your initial write. These defragmentation moves need to be atomic, so you need to be writing some other metadata on the disk. Not only that, we're doing *far* more seeking. Seeking is mind-blowingly expensive compared to writing that chunk of data from before, and the fact that we have to flush the buffers frequently to keep things atomic means that we can't combine as many writes, which means worse seeking.

      Without a real world implementation with numbers, it's hard to show you how bad this would be, but every filesystem I've ever used would be far, far, far faster than this.

    2. Re:Fragmentation. by 0x0d0a · · Score: 3, Insightful

      ARRRRRGGGGHHHH!

      I'd rather see this implemented in ext3 than ext2 for the obvious journalling benefits

      Okay. First, implementing this in ext3 would be almost meaningless. The entire point of journalling is that you always write *forward* on the disk, and update pointers to the newest data. Your writes are nearly always contiguous in ext3. This system, where you have to overwrite positions containing deleted files, would have to dance from location to location on the disk to write a file. Very expensive. You could make an atomic writes filesystem, but it probably wouldn't be smart to make it journalling.

      Also, I definitely do not feel that a performance hit would be noticeable. The Novell file system is still BLAZING fast despite the fact taht it is managing hundreds of thousands of deleted files

      The number of deleted files isn't the issue -- it's how much free space you have available. I can assure you that the Novell guys aren't taking your approach -- only overwriting something when they absolutely have to do so.

      The filesystem would still control fragmentation, just as it does today.

      What impact does this have on performance? If you're thinking that ext2 does background defragmentation, it doesn't.

      The fragmentation issues stem entirely from the lack of free space -- the file system always has an extremely small amount of free space. That free space is likely scattered around the disk.

      I'm not sure of all the ways that ext2 differs from vanilla UFS, but I strongly suspect that ext2 does not have a distinct allocated block list. In any event, a one-table or two-table question really isn't an issue.

      Finally, let me reiterate: FREE SPACE. Between about 80% or 90% full, ext2/3 filesystem performance starts to take a nasty hit from fragmentation. If your filesystem is 99% full, you're going to be getting quite fragmented. If you are using the proposed system, you always have just a few killobytes of free space (the space left over in what used to be the oldest deleted file).

  20. Re:Possible solution. by Loki_1929 · · Score: 3, Insightful

    "As a user I don't push the drives hard enough to notice a difference. I'm not running a high traffic web server, I'm editing documents."

    And that's fine, but don't assume that your particular usage is indicative of the vast majority of the masses. I do happen to use my hard drives, often pushing them to the point where the cpu is sitting at 20% waiting for the drive to feed it some data.

    "The drive doesn't give a damn what those bits are, it has no concept of full or empty, it just reads and writes where its told. Your filesystem may have issues when you hit 50-80% capacity, but that doesn't have anything to do with the drive."

    Well, if you'd like to get technical (as well as snitty), the drive has no "concept" of anything, as that would pre-suppose cognizance. In any event, if you look through any of a number of benchmarks (I personally like HDTach) which may either use a filesystem or not use one to do their work, you'll see that where you're reading/writing on the drive does have an effect on the performance. The filesystem generally cares only in that the fragmentation level tends to be higher at high disk usage, and it becomes increasingly difficult to defragment a drive as the free space dwindles.

    I'm not sure what you'd like to call a "typical desktop system", but I can tell you that if you take two systems with identical specs except that one has a 2GB 5400RPM drive with 10MB free, and use it along side another with a 36GB Cheetah X15 with 35GB free space, you'll see a remarkable improvement in many fields, especially games, photo/video/sound editing software, and anything else that requires writes/reads from the hard disk and/or swap file. If you don't think that the performance difference matters most of the time, then I think you ought to send a resume to Redmond, WA, as I'm sure you're just the kind of person they're looking for there.

    --
    -- "Government is the great fiction through which everybody endeavors to live at the expense of everybody else."