Re: [opensuse] Undoing a delete
![](https://seccdn.libravatar.org/avatar/d10fc27544c12cb85a0f627f0fd9bdde.jpg?s=120&d=mm&r=g)
On Sat, 2007-11-17 at 15:30 -0800, Randall R Schulz wrote:
On Saturday 17 November 2007 14:40, Bryen wrote:
Is there any way to undo an rm in terminal? Probably not, but thought I'd ask...
The short answer is "no." There's no "trashcan" or "wastebin" involved. Only with tremendous luck and heroic effort could you hope to recover the contents of the file to which you applied the stock "rm" command.
You'd think, since I googled and see enough people have done this same thing accidentally, that a trashcan folder would be standard. Oh well...
I've known users (dare I say, "lusers") to override rm with a script that moves the target files to a trashcan folder.
Hmm... That would be an interesting project to try to create. What a way for me to flex my current knowledge and expand on it. :-)
I don't suppose it will be long now before we have a Linux counterpart to the latest Mac OS's "Time Machine" functionality.
There's a python script that I downloaded a few weeks ago but haven't really tried it yet. It is supposed to mimic TimeMachine. It's called Flyback. You can find it at http://code.google.com/p/flyback/ Maybe I better look at it again now before I screw anything else up! :-) -- ---Bryen--- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
![](https://seccdn.libravatar.org/avatar/7574aaee71d8971a36f4283a7cad6b2c.jpg?s=120&d=mm&r=g)
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
* Bryen
You'd think, since I googled and see enough people have done this same thing accidentally, that a trashcan folder would be standard. Oh well...
there is and it is, but that is a graphical thing and *can* be bypassed, but it does not save you from command line rm. a deterrent, alias rm='/bin/rm -i' - -- Patrick Shanahan Plainfield, Indiana, USA HOG # US1244711 http://wahoo.no-ip.org Photo Album: http://wahoo.no-ip.org/gallery2 Registered Linux User #207535 @ http://counter.li.org -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) iD8DBQFHP36XClSjbQz1U5oRAtIqAJ4ltXIbvMBre2Mr+5TkCim4dtzXlwCfU5Zn d7k517NVdxm1OQo0k6h8G0Q= =9dUM -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
![](https://seccdn.libravatar.org/avatar/d10fc27544c12cb85a0f627f0fd9bdde.jpg?s=120&d=mm&r=g)
On Sat, 2007-11-17 at 18:51 -0500, Patrick Shanahan wrote:
* Bryen
[11-17-07 18:44]: You'd think, since I googled and see enough people have done this same thing accidentally, that a trashcan folder would be standard. Oh well...
there is and it is, but that is a graphical thing and *can* be bypassed, but it does not save you from command line rm.
a deterrent, alias rm='/bin/rm -i'
That's a good idea, and I'm going to do just that. Although, in this case, it probably wouldn't have worked perfectly. I assumed I was in a different directory and ran rm *. I rm'ed when I wanted to, just not WHERE I wanted to. :-) This is what happens when you're holed up on a Saturday afternoon writing scripts instead of playing outside. -- ---Bryen--- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
![](https://seccdn.libravatar.org/avatar/9274377d580dfa6a312e185f924c6e32.jpg?s=120&d=mm&r=g)
* Bryen
[11-17-07 18:44]: You'd think, since I googled and see enough people have done this same thing accidentally, that a trashcan folder would be standard. Oh well...
there is and it is, but that is a graphical thing and *can* be bypassed, but it does not save you from command line rm.
a deterrent, alias rm='/bin/rm -i' I remember another approach: http://pages.stern.nyu.edu/~marriaga/software/libtrash Basically it intercepts syscalls like "unlink", etc. and replaces
Patrick Shanahan wrote: them with its own implementations. Somebody out there who's tried this ? Rgds, Stephan. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
![](https://seccdn.libravatar.org/avatar/f32266cfb594b651f542aa948e25f2a3.jpg?s=120&d=mm&r=g)
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Stephan Hegel wrote:
* Bryen
[11-17-07 18:44]: a deterrent, alias rm='/bin/rm -i' I remember another approach: http://pages.stern.nyu.edu/~marriaga/software/libtrash Basically it intercepts syscalls like "unlink", etc. and replaces Patrick Shanahan wrote: them with its own implementations.
Somebody out there who's tried this ?
I seem to recall from the days preceding recorded history of my linux usage that libtrash had some problem with mutt. In any case, when you use libtrash you'll still have to empty the trash periodically, and then someone will empty trash containing a file they wanted and the thread topic will be "undoing a libtrash delete" rather than "Undoing a delete" :) It's really aliasing rm which is the most effective solution, coupled with backups. JA - -- http://www.DonAssad.com jabber ID: josef.assad@gmail.com Please consider the environment; do you really need to print out this e-mail? -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.4-svn0 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iD8DBQFHQB32Fcf72sjD2+QRAjrMAJ9PlUUczU76ZJNni849/Bsr7JgJpACfcJ5h z4IBqTdLxxWmZ+WQSbIM/qE= =fdnG -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
![](https://seccdn.libravatar.org/avatar/d10fc27544c12cb85a0f627f0fd9bdde.jpg?s=120&d=mm&r=g)
On Sun, 2007-11-18 at 13:11 +0200, Josef Assad wrote:
In any case, when you use libtrash you'll still have to empty the trash periodically, and then someone will empty trash containing a file they wanted and the thread topic will be "undoing a libtrash delete" rather than "Undoing a delete" :)
The phrase "Fool me once, shame on you. Fool me twice, shame on me." comes to mind here. To have deleted the file once accidentally, well that can happen to anyone. But to then delete the file yet again from trash... well shame on you. :-) -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
![](https://seccdn.libravatar.org/avatar/ef3b20e499e909bd7574513744103ce3.jpg?s=120&d=mm&r=g)
On Sat, 2007-11-17 at 18:51 -0500, Patrick Shanahan wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
* Bryen
[11-17-07 18:44]: You'd think, since I googled and see enough people have done this same thing accidentally, that a trashcan folder would be standard. Oh well...
there is and it is, but that is a graphical thing and *can* be bypassed, but it does not save you from command line rm.
a deterrent, alias rm='/bin/rm -i'
Shouldn't that be in dot profile or dot bashrc so it persists between konsole secessions? ___ _ _ _ ____ _ _ _ | | | | [__ | | | |___ |_|_| ___] | \/ -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
![](https://seccdn.libravatar.org/avatar/b12cfb65ca4faebc3e3aac17838e8f8d.jpg?s=120&d=mm&r=g)
On Saturday 17 November 2007 15:41, Bryen wrote:
On Sat, 2007-11-17 at 15:30 -0800, Randall R Schulz wrote:
...
I've known users (dare I say, "lusers") to override rm with a script that moves the target files to a trashcan folder.
Hmm... That would be an interesting project to try to create. What a way for me to flex my current knowledge and expand on it. :-)
It's no big deal. Write an "rm" replacement script that moves files to a specified trash folder rather than simply unlink them. The only thing you really have to worry about is name clashes. When that happens, add a suffix (making sure that the suffix is unique, of course). With a bit more work, you could additionally mimic the file system hierarchy within the trash folder, but that doesn't get you out of handling multiple deletes of the same name (since files often get recreated after they're deleted).
I don't suppose it will be long now before we have a Linux counterpart to the latest Mac OS's "Time Machine" functionality.
There's a python script that I downloaded a few weeks ago but haven't really tried it yet. It is supposed to mimic TimeMachine. It's called Flyback. You can find it at http://code.google.com/p/flyback/
I doubt tremendously (i.e., I flatly don't believe) that Python can be used to implement Time Machine. Doing that will require some low-level hooks.
Maybe I better look at it again now before I screw anything else up! :-)
It could be both useful and educational, so yes, go for it.
-- ---Bryen---
Randall Schulz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
![](https://seccdn.libravatar.org/avatar/d10fc27544c12cb85a0f627f0fd9bdde.jpg?s=120&d=mm&r=g)
On Sat, 2007-11-17 at 15:53 -0800, Randall R Schulz wrote:
On Saturday 17 November 2007 15:41, Bryen wrote:
On Sat, 2007-11-17 at 15:30 -0800, Randall R Schulz wrote:
...
I've known users (dare I say, "lusers") to override rm with a script that moves the target files to a trashcan folder.
Hmm... That would be an interesting project to try to create. What a way for me to flex my current knowledge and expand on it. :-)
It's no big deal. Write an "rm" replacement script that moves files to a specified trash folder rather than simply unlink them. The only thing you really have to worry about is name clashes. When that happens, add a suffix (making sure that the suffix is unique, of course). With a bit more work, you could additionally mimic the file system hierarchy within the trash folder, but that doesn't get you out of handling multiple deletes of the same name (since files often get recreated after they're deleted).
So how would a script called rm not conflict with the real rm McCoy? Nothing to you, but I'm just starting to get into scripting. :-) Critique me here. As I'm going by theory. I would move the current /bin/rm to a new location. Then I would create an rm script and place it in /bin where the current rm was located. But within the rm script, I would point to the rm command's full path when using rm's functionality. Thus users would never see the difference when they run /bin/rm, but the script does the interpretation to /somewherelse/rm. Did I figure it out right? -- ---Bryen--- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
![](https://seccdn.libravatar.org/avatar/b12cfb65ca4faebc3e3aac17838e8f8d.jpg?s=120&d=mm&r=g)
On Saturday 17 November 2007 16:24, Bryen wrote:
On Sat, 2007-11-17 at 15:53 -0800, Randall R Schulz wrote:
On Saturday 17 November 2007 15:41, Bryen wrote:
On Sat, 2007-11-17 at 15:30 -0800, Randall R Schulz wrote:
...
I've known users (dare I say, "lusers") to override rm with a script that moves the target files to a trashcan folder.
Hmm... That would be an interesting project to try to create. What a way for me to flex my current knowledge and expand on it. :-)
It's no big deal. Write an "rm" replacement script that moves files to a specified trash folder rather than simply unlink them. ...
So how would a script called rm not conflict with the real rm McCoy? Nothing to you, but I'm just starting to get into scripting. :-)
It's a matter of precedence. You put the replacement "rm" in a directory that is checked before the stock one (/bin).
Critique me here. As I'm going by theory. I would move the current /bin/rm to a new location.
Whoa! No, no no. Never do that!! No, just create a directory ~/bin (equally, $HOME/bin) and put your personal scripts there. Make sure that directory precedes the stock directories in the PATH variable. (I don't recall if $HOME/bin is part of the stock PATH or not, but if it isn't, add a line like this to your "$HOME/.bash_profile" script: PATH="$HOME/bin:$PATH"
Then I would create an rm script and place it in /bin where the current rm was located.
No. Put it in ~/bin ($HOME/bin).
But within the rm script, I would point to the rm command's full path when using rm's functionality.
Well, the point is to avoid what the stock "rm" does and instead move the file to an out-of-the-way place from which you can retrieve it should you change your mind.
Thus users would never see the difference when they run /bin/rm, but the script does the interpretation to /somewherelse/rm.
Did I figure it out right?
Uh. Keep trying. Perhaps for someone as new to all this as you, playing around with replacements for key OS utilities isn't the best idea. You could use Konqueror or ... what's it called? There's a Gnome file manager, too. They're GUIs that have trash cans and "Empty Trash" commands and all that usual stuff.
-- ---Bryen---
Randall Schuzl -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
![](https://seccdn.libravatar.org/avatar/d10fc27544c12cb85a0f627f0fd9bdde.jpg?s=120&d=mm&r=g)
On Sat, 2007-11-17 at 16:32 -0800, Randall R Schulz wrote:
Critique me here. As I'm going by theory. I would move the current /bin/rm to a new location.
Whoa! No, no no. Never do that!!
No, just create a directory ~/bin (equally, $HOME/bin) and put your personal scripts there. Make sure that directory precedes the stock directories in the PATH variable. (I don't recall if $HOME/bin is part of the stock PATH or not, but if it isn't, add a line like this to your "$HOME/.bash_profile" script:
PATH="$HOME/bin:$PATH"
Then I would create an rm script and place it in /bin where the current rm was located.
No. Put it in ~/bin ($HOME/bin).
But within the rm script, I would point to the rm command's full path when using rm's functionality.
Well, the point is to avoid what the stock "rm" does and instead move the file to an out-of-the-way place from which you can retrieve it should you change your mind.
Thus users would never see the difference when they run /bin/rm, but the script does the interpretation to /somewherelse/rm.
Did I figure it out right?
Uh. Keep trying.
Perhaps for someone as new to all this as you, playing around with replacements for key OS utilities isn't the best idea.
You could use Konqueror or ... what's it called? There's a Gnome file manager, too. They're GUIs that have trash cans and "Empty Trash" commands and all that usual stuff.
I'm not that new. Just new to scripting itself within Linux, but willing to take my chances and experiment (even break) to further my knowledge. As for GUI (Nautilus on GNOME), as Patrick pointed out, when rm-ing on the command line, it doesn't fall into the GUI trash can. Only when you delete within GUI. I double-verified this just to be sure. I didn't realize that you could create ~/bin which would take precedence over standard /bin. Now that I know, I can proceed a bit more safely. To me, this is an excellent trial/error exercise that coincides perfectly with my scripting studies. And I do appreciate the feedback you've given. Lots of good foundational information from you. I thank you. -- ---Bryen--- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
![](https://seccdn.libravatar.org/avatar/ef3b20e499e909bd7574513744103ce3.jpg?s=120&d=mm&r=g)
On Sat, 2007-11-17 at 15:53 -0800, Randall R Schulz wrote:
On Saturday 17 November 2007 15:41, Bryen wrote:
On Sat, 2007-11-17 at 15:30 -0800, Randall R Schulz wrote:
...
I've known users (dare I say, "lusers") to override rm with a script that moves the target files to a trashcan folder.
Hmm... That would be an interesting project to try to create. What a way for me to flex my current knowledge and expand on it. :-)
It's no big deal. Write an "rm" replacement script that moves files to a specified trash folder rather than simply unlink them. The only thing you really have to worry about is name clashes. When that happens, add a suffix (making sure that the suffix is unique, of course). With a bit more work, you could additionally mimic the file system hierarchy within the trash folder, but that doesn't get you out of handling multiple deletes of the same name (since files often get recreated after they're deleted).
Here is an easy bash script one dates files the other takes a prefix. change cp to mv and pick your target directory. With command pwd you get the present working directory so if you later go to your trash directory you can read where the file came from. cat CopyWithDate.sh #!/bin/sh for i in `ls -A`; do cp -v $i /home/cwsiv/Documents/$(date +%F).$i; done cat CopyWithPrefix.sh #!/bin/sh echo Needs detection for empty string if [$1=""]; then echo Provide a Prefix to be used fi #for i in `ls -A`; do # cp -v $i /home/cwsiv/Documents/$1.$i; #done ___ _ _ _ ____ _ _ _ | | | | [__ | | | |___ |_|_| ___] | \/ -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
![](https://seccdn.libravatar.org/avatar/64da0fec7f607877d5d2c4f6e5593d8b.jpg?s=120&d=mm&r=g)
There is a remote possibility if you haven't rebooted or done anything dramatic since the delete. http://www.linux.com/articles/58142 Paul Bryen wrote:
On Sat, 2007-11-17 at 15:30 -0800, Randall R Schulz wrote:
On Saturday 17 November 2007 14:40, Bryen wrote:
Is there any way to undo an rm in terminal? Probably not, but thought I'd ask...
The short answer is "no." There's no "trashcan" or "wastebin" involved. Only with tremendous luck and heroic effort could you hope to recover the contents of the file to which you applied the stock "rm" command.
You'd think, since I googled and see enough people have done this same thing accidentally, that a trashcan folder would be standard. Oh well...
I've known users (dare I say, "lusers") to override rm with a script that moves the target files to a trashcan folder.
Hmm... That would be an interesting project to try to create. What a way for me to flex my current knowledge and expand on it. :-)
I don't suppose it will be long now before we have a Linux counterpart to the latest Mac OS's "Time Machine" functionality.
There's a python script that I downloaded a few weeks ago but haven't really tried it yet. It is supposed to mimic TimeMachine. It's called Flyback. You can find it at http://code.google.com/p/flyback/
Maybe I better look at it again now before I screw anything else up! :-)
-- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (7)
-
Bryen
-
Carl Spitzer
-
Josef Assad
-
Patrick Shanahan
-
Paul Hands
-
Randall R Schulz
-
Stephan Hegel