Re: undelete in FreeBSD?
Xu Qiang wrote: ... is the lack of a cyclin bin, from which you can restore anything you have mis-deleted before. Or, am I mis-informed on this issue? I scratched my head about it too and finally wrote a simple script which moves trashed items into auto made date-stamped directories. I can send it later, if there's interest. -- Regards, Karel Miklav ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: undelete in FreeBSD?
Hi, this tip is taken from BSD hacks book(http://www.amazon.com/exec/obidos/tg/detail/-/0596006799/002-3776521-4670458?v=glance) Create a Trash Directory Save deleted files until you're really ready to send them to the bit bucket. One of the first things Unix users learn is that deleted files are really, really gone. This is especially true at the command line where there isn't any Windows-style recycling bin to rummage through should you have a change of heart regarding the fate of a removed file. It's off to the backups! (You do have backups, don't you?) Fortunately, it is very simple to hack a small script that will send removed files to a custom trash directory. If you've never written a script before, this is an excellent exercise in how easy and useful scripting can be. Since a script is an executable file, you should place your scripts in a directory that is in your path. Remember, your path is just a list of directories where the shell will look for commands if you don't give them full pathnames. To see your path: % echo $PATH PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/ local/bin:/usr/X11R6/bin:/home/dru/bin In this output, the shell will look for executables in the bin subdirectory of dru's home directory. However, it won't look for executables placed directly in my home directory, or /home/dru. Since bin isn't created by default, I should do that first: % cd % mkdir bin As I create scripts, I'll store them in /home/dru/bin, since I don't have permission to store them anywhere else. Fortunately, no one else has permission to store them in my bin directory, so it's a good match. The scripts themselves contain at least three lines: #!/bin/sh # a comment explaining what the script does the command to be executed The first line indicates the type of script by specifying the program to use to execute the script. I've chosen to use a Bourne script because that shell is available on all Unix systems. Your script should also have comments, which start with the # character. It's surprising how forgetful you can be six months down the road, especially if you create a lot of scripts. For this reason, you should also give the script a name that reminds you of what it does. The third and subsequent lines contain the meat of the script: the actual command(s) to execute. This can range from a simple one-liner to a more complex set of commands, variables, and conditions. Fortunately, we can make a trash script in a simple one-liner. Let's start with this variant, which I found as the result of a Google search: % more ~/bin/trash #!/bin/sh # script to send removed files to trash directory mv $1 ~/.trash/ You should recognize the path to the Bourne shell, the comment, and the mv command. Let's take a look at that $1. This is known as a positional parameter and specifically refers to the first parameter of the trash command. Since the mv commands takes filenames as parameters, the command: mv $1 ~/.trash/ is really saying, mv the first filename, whatever it happens to be, to a directory called .trash in the user's home directory (represented by the shell shortcut of ~). This move operation is our custom recycle. Before this script can do anything, it must be set as executable: % chmod +x ~/bin/trash And I must create that trash directory for it to use: % mkdir ~/.trash Note that I've chosen to create a hidden trash directory; any file or directory that begins with the . character is hidden from normal listings. This really only reduces clutter, though, as you can see these files by passing the -a switch to ls. If you also include the F switch, directory names will end with a /: % ls -aF ~ .cshrc .history .trash/ bin/ images/ myfile Now comes the neat part of the hack. I want this script to kick in every time I use rm. Since it is the shell that executes commands, I simply need to make my shell use the trash command instead. I do that by adding this line to ~/.cshrc: alias rm trash That line basically says: when I type rm, execute trash instead. It doesn't matter which directory I am in. As long as I stay in my shell, it will mv any files I try to rm to my hidden trash directory. Whenever you create a script, always test it first. I'll start by telling my shell to reread its configuration file: % source ~/.cshrc Then, I'll make some test files to remove: % cd % mkdir test % cd test % touch test1 % rm test1 % ls ~/.trash test1 Looks like the script is working. However, it has a flaw. Have you spotted it yet? If not, try this: % touch a aa aaa % rm a* % ls ~/.trash test1 a % ls test aa aaa What happened here? I passed the shell more than one parameter. The a* was expanded to a, aa, aaa, and before trash could execute. Those four parameters were then passed on to the mv command in my script. However, trash passes only the first parameter to the mv command, ignoring the remaining parameters. Fortunately, they weren't
Re: undelete in FreeBSD?
Peter wrote: this tip is taken from BSD hacks I do not believe this! This girl literally stole my script, traveled back through time to cover the tracks and made an article out of her shameless act :) Anyway, here's the original version of 'the trash': #! /bin/sh # Move files in a trash folder. trash_root=$HOME/.trash trash_stamp=`date +%Y%m%d%H%M%S` trash_dest=$trash_root/$trash_stamp if [ ! -d $trash_root ]; then mkdir -p $trash_root fi if [ -e $trash_dest ]; then echo Ups, $trash_dest exists! else mkdir $trash_dest mv $@ $trash_dest/ echo Files trashed. fi -- Regards, Karel Miklav ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
RE: undelete in FreeBSD?
Ross Kendall Axe wrote: Yes. MS-Windows doesn't have anything Unix doesn't in this regard. I take it you're not familiar with the DOS/Windows 'del' command... Hehe, this is a good analog I didn't think of. :) If he's worried about accidentally deleting files, he should use KDE or Gnome. They both have a trash can/wastebasket/recycle bin. Now I just have X Window in my machine. Not as good-looking as Gnome desktop. Can I install gnome without using ports? I want to install everything manually. thanks, Regards, Xu Qiang ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
RE: undelete in FreeBSD?
At 10:48 PM 7/25/2005, Xu Qiang wrote: Ross Kendall Axe wrote: Yes. MS-Windows doesn't have anything Unix doesn't in this regard. I take it you're not familiar with the DOS/Windows 'del' command... Hehe, this is a good analog I didn't think of. :) If he's worried about accidentally deleting files, he should use KDE or Gnome. They both have a trash can/wastebasket/recycle bin. Now I just have X Window in my machine. Not as good-looking as Gnome desktop. Can I install gnome without using ports? I want to install everything manually. Are you a glutton for punishment? You can install it manually, I did it once...never again. Seriously though, there are so many dependencies that it takes forever to get everything set up manually. With ports you just do a make install clean and come back in a few hours (or days depending on how fast your machine is) -Glenn thanks, Regards, Xu Qiang --- We've checked and double checked, it keeps coming up the same thing. The message is Mars needs women. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: undelete in FreeBSD?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Glenn Dawson wrote: At 10:48 PM 7/25/2005, Xu Qiang wrote: Ross Kendall Axe wrote: Yes. MS-Windows doesn't have anything Unix doesn't in this regard. I take it you're not familiar with the DOS/Windows 'del' command... Hehe, this is a good analog I didn't think of. :) If he's worried about accidentally deleting files, he should use KDE or Gnome. They both have a trash can/wastebasket/recycle bin. Now I just have X Window in my machine. Not as good-looking as Gnome desktop. Can I install gnome without using ports? I want to install everything manually. Are you a glutton for punishment? You can install it manually, I did it once...never again. Seriously though, there are so many dependencies that it takes forever to get everything set up manually. With ports you just do a make install clean and come back in a few hours (or days depending on how fast your machine is) Yes, indeed. I've never tried it myself, but the fact that it's been dropped from Slackware Linux for exactly this reason would seem to suggest that this is *not* an exercise for the faint hearted. Ross -Glenn thanks, Regards, Xu Qiang -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.7 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFC5q239bR4xmappRARAouvAKDctUkF4wkn9L6bm/GeB99arjuEmQCgoEoZ qzqjmPM9uodBwBxUuTSC64o= =OQGq -END PGP SIGNATURE- ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
RE: undelete in FreeBSD?
Glenn Sieb wrote: Nelis Lamprecht said the following on 7/21/2005 5:13 AM: There isn't a way to restore unless you have a backup. However, most of the binary files in /usr/local/bin are from packages/ports you have installed on your system. So you may be able to get away with using portupgrade(/usr/ports/sysutils/portupgrade) to re-install those packages and therefore restoring some if not all of /usr/local/bin. Do a portupgrade -f -a which forces portupgrade to re-install all packages/ports you have currently installed. Nelis, First I think he might have to go re-install portupgrade. Xu--as root, perform the following steps: cd /tmp tar cvf etc.tar /usr/local/etc/ cd /usr/ports/sysutils/portupgrade make install make clean portupgrade -farRx bsdpan- This will force reinstallation of all your ports. This will take *forever*. And, just in case, we've tarred up your /usr/local/etc directory so you have a backup in /tmp! Thanks for all who helped. I am just wondering the only shortcoming of Unix clone, such as FreeBSD, in contrast to M$ Windows, is the lack of a cyclin bin, from which you can restore anything you have mis-deleted before. Or, am I mis-informed on this issue? Regards, Xu Qiang ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
RE: undelete in FreeBSD?
At 07:51 PM 7/25/2005, Xu Qiang wrote: I am just wondering the only shortcoming of Unix clone, such as FreeBSD, in contrast to M$ Windows, is the lack of a cyclin bin, from which you can restore anything you have mis-deleted before. Or, am I mis-informed on this issue? If you're really worried about accidently deleting files, just make rm an alias to 'rm -i' or 'rm -I' -Glenn Regards, Xu Qiang ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED] ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: undelete in FreeBSD?
Glenn Dawson wrote: At 07:51 PM 7/25/2005, Xu Qiang wrote: I am just wondering the only shortcoming of Unix clone, such as FreeBSD, in contrast to M$ Windows, is the lack of a cyclin bin, from which you can restore anything you have mis-deleted before. Or, am I mis-informed on this issue? If you're really worried about accidently deleting files, just make rm an alias to 'rm -i' or 'rm -I' -Glenn Regards, Xu Qiang ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED] ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED] Also check out chflags. Under certain security levels, you can set flags so that something can not be deleted even as root. Casey ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: undelete in FreeBSD?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Glenn Dawson wrote: At 07:51 PM 7/25/2005, Xu Qiang wrote: I am just wondering the only shortcoming of Unix clone, such as FreeBSD, in contrast to M$ Windows, is the lack of a cyclin bin, from which you can restore anything you have mis-deleted before. Or, am I mis-informed on this issue? Yes. MS-Windows doesn't have anything Unix doesn't in this regard. I take it you're not familiar with the DOS/Windows 'del' command... If you're really worried about accidently deleting files, just make rm an alias to 'rm -i' or 'rm -I' If he's worried about accidentally deleting files, he should use KDE or Gnome. They both have a trash can/wastebasket/recycle bin. Ross -Glenn Regards, Xu Qiang -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.7 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFC5cyW9bR4xmappRARAn2wAKC3oB1B2bgveSvb1F/1TBW1B4yETQCgkeVm 26L4uYUs/oqfF2YUVdTIyEU= =jYHH -END PGP SIGNATURE- ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: undelete in FreeBSD?
On 07/24/05 07:16 AM, Mario Hoerich sat at the `puter and typed: # Aaron Siegel: [ there is no un-rm ] One option I have seen for creating your own restore is to create a script that will move files you want to delete to a temporary directory, a Trash Bin. Then use your shells aliases to alias the script to the rm command. Don't *ever* create aliases for rm(1). rm's sole purpose in life is to destroy files. If you tame it, you'll eventually adapt and rm with less caution. There are lots of people who eventually got bitten by that when working on a machine other than their own. A better way is to use a name like [tT]rash or tt (=[move] to trash). That way, when working on a machine without your script, you'll get a nice and friendly command not found reminding you there's no safety catch. I'm personally none too fond of this, though. Unixoid systems have quite a lot of ways to destroy files. Trashes won't really protect you from that. Instead, they just give you a false feeling of security, which merely encourages sloppiness. My own solution is actually quite simple: I treat dangerous commands the same way I'd carry a deadly and pretty annoyed snake: with my thoughts on the task at hand. I read the command *before* I hit enter. Not the one I *think* I've written, but the one I'm about to execute. I also tend to tab-expand globs to see which files are actually affected. YMMV, though. I have to second this - every bit of it. Deleting files is not an area you want to get sloppy in. I've been bitten even knowing rm would get rid of these files for good. I once fatfingered a space between a '*' and '.txt' and lost a weeks worth of code work in one fell swoop. Trust me, it's a mistake you make once and kick yourself for indefinitely. Trust me, I tend to use rm very carefully now, re-reading the command each time I use it. And no, I don't believe I'm making the case for a trash function. I think that would increase the chances of sloppiness. After the incident mentioned above, I considered the trash function, and eventually came to the same conclusions Mario mentioned above. Lou -- Louis LeBlanc FreeBSD-at-keyslapper-DOT-net Fully Funded Hobbyist, KeySlapper Extrordinaire :) Please send off-list email to: leblanc at keyslapper d.t net Key fingerprint = C5E7 4762 F071 CE3B ED51 4FB8 AF85 A2FE 80C8 D9A2 First study the enemy. Seek weakness. -- Romulan Commander, Balance of Terror, stardate 1709.2 pgpCxQsePzsRk.pgp Description: PGP signature
Re: undelete in FreeBSD?
Hello One option I have seen for creating your own restore is to create a script that will move files you want to delete to a temporary directory, a Trash Bin. Then use your shells aliases to alias the script to the rm command. On Thursday 21 July 2005 1:07 am, Xu Qiang wrote: Hi, all: I mis-deleted /usr/local/bin directory in my FreeBSD. How can I restore it? Looking for your help urgently, thanks, Xu Qiang ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED] ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: undelete in FreeBSD?
# Aaron Siegel: [ there is no un-rm ] One option I have seen for creating your own restore is to create a script that will move files you want to delete to a temporary directory, a Trash Bin. Then use your shells aliases to alias the script to the rm command. Don't *ever* create aliases for rm(1). rm's sole purpose in life is to destroy files. If you tame it, you'll eventually adapt and rm with less caution. There are lots of people who eventually got bitten by that when working on a machine other than their own. A better way is to use a name like [tT]rash or tt (=[move] to trash). That way, when working on a machine without your script, you'll get a nice and friendly command not found reminding you there's no safety catch. I'm personally none too fond of this, though. Unixoid systems have quite a lot of ways to destroy files. Trashes won't really protect you from that. Instead, they just give you a false feeling of security, which merely encourages sloppiness. My own solution is actually quite simple: I treat dangerous commands the same way I'd carry a deadly and pretty annoyed snake: with my thoughts on the task at hand. I read the command *before* I hit enter. Not the one I *think* I've written, but the one I'm about to execute. I also tend to tab-expand globs to see which files are actually affected. YMMV, though. Cheers, Mario ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: undelete in FreeBSD?
Nelis Lamprecht said the following on 7/21/2005 5:13 AM: On 7/21/05, Xu Qiang [EMAIL PROTECTED] wrote: Hi, all: I mis-deleted /usr/local/bin directory in my FreeBSD. How can I restore it? There isn't a way to restore unless you have a backup. However, most of the binary files in /usr/local/bin are from packages/ports you have installed on your system. So you may be able to get away with using portupgrade(/usr/ports/sysutils/portupgrade) to re-install those packages and therefore restoring some if not all of /usr/local/bin. Do a portupgrade -f -a which forces portupgrade to re-install all packages/ports you have currently installed. Nelis, First I think he might have to go re-install portupgrade. Xu--as root, perform the following steps: cd /tmp tar cvf etc.tar /usr/local/etc/ cd /usr/ports/sysutils/portupgrade make install make clean portupgrade -farRx bsdpan- This will force reinstallation of all your ports. This will take *forever*. And, just in case, we've tarred up your /usr/local/etc directory so you have a backup in /tmp! Good luck!! Best, --Glenn -- They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety. ~Benjamin Franklin, Historical Review of Pennsylvania, 1759 ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: undelete in FreeBSD?
On 7/21/05, Xu Qiang [EMAIL PROTECTED] wrote: Hi, all: I mis-deleted /usr/local/bin directory in my FreeBSD. How can I restore it? Looking for your help urgently, thanks, Xu Qiang Use your backups, you do make backups dont you? ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
RE: undelete in FreeBSD?
Hornet wrote: On 7/21/05, Xu Qiang [EMAIL PROTECTED] wrote: Hi, all: I mis-deleted /usr/local/bin directory in my FreeBSD. How can I restore it? Looking for your help urgently, thanks, Xu Qiang Use your backups, you do make backups dont you? Never backup /usr/local/bin directory. :( And I don't have backup for the whole system. :((( Regards, Xu Qiang ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: undelete in FreeBSD?
On 7/21/05, Xu Qiang [EMAIL PROTECTED] wrote: Hi, all: I mis-deleted /usr/local/bin directory in my FreeBSD. How can I restore it? There isn't a way to restore unless you have a backup. However, most of the binary files in /usr/local/bin are from packages/ports you have installed on your system. So you may be able to get away with using portupgrade(/usr/ports/sysutils/portupgrade) to re-install those packages and therefore restoring some if not all of /usr/local/bin. Do a portupgrade -f -a which forces portupgrade to re-install all packages/ports you have currently installed. Good luck. Nelis ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]