Operating System - HP-UX
1753428 Members
4809 Online
108793 Solutions
New Discussion юеВ

Re: problem after rm -rf *

 
SOLVED
Go to solution
Bill Hassell
Honored Contributor
Solution

Re: problem after rm -rf *

Congratulations! You are now a member of the "rm -rf *" Club. There are many members, most of them are sadder but wiser system administrators (or unemployed). There are a couple of additional Clubs for you to join (if you haven't already become a member):

The "chmod -R 777 *" club
The "chown -R root:bin *" Club

As mentioned, the "/" directory is the *WORST* possible location for root's HOME yet unfortunately, this is the default for virtually all flavors of UNIX. Never cd to / unless you are shutting down. Never execute any command that can recursively act on files and directories until you have previewed the command (ie, rm -i *) and now that you know the consequences, put these aliases in /etc/profile:

alias rm="/usr/bin/rm -i"
alias cp="/usr/bin/cp -i"
alias mv="/usr/bin/mv -i"

This will help immensely by prompting you with something like this:

rm -i -rf *
/stand/vmunix: ? [y/n]

AS you might expect, it would be a bad thing to remove /stand/vmunix...etc.

Another really useful command is: type

This is actually an alias to "whence -v" and is the only useful way to determine what will be run when you type a command. In your case:

# type pwd cd ls
pwd is a shell builtin.
cd is a shell builtin.
ls is /usr/bin/ls

The commands: which and whereis are useless in telling you what will happen in the shell. For instance, in my shell, I get this:

pwd is an alias for /usr/bin/pwd
cd is a shell builtin.
ls is an alias for /usr/bin/ls -aF

In other words, I am *NOT* running the 'normal' commands because I have aliased pwd and ls. The reason for pwd is to show the 'real' directory when using cd in the shell to follow a transition link. For example:

$ cd /usr/spool/lp/interface
$ type pwd
pwd is a shell builtin.
$ pwd
/usr/spool/lp/interface
$ /usr/bin/pwd
/etc/lp/interface

The shell can be a bit misleading at times...


Bill Hassell, sysadmin
prasadb
Super Advisor

Re: problem after rm -rf *

thank you all..

Bill i was just wondering to know what is

The "chmod -R 777 *" club
The "chown -R root:bin *" Club are all about ?

can you throw some light on these ?

Yogeeraj_1
Honored Contributor

Re: problem after rm -rf *

hi,

>The "chmod -R 777 *" club
>The "chown -R root:bin *" Club are all about ?


these were just anecdots that Bill has used just to say that there have been people before you who have had the same incident before. So, you are not the privileged member of this club... :)


Nothing to worry about. It was just a joke!

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Venkatesh BL
Honored Contributor

Re: problem after rm -rf *


>The "chmod -R 777 *" club
>The "chown -R root:bin *" Club are all about ?

Please don't try this!, else, you may have to post one more query :)
prasadb
Super Advisor

Re: problem after rm -rf *

thanx yogiraj, and all who gave me their precious time to answer my doubts and question...
Dennis Handly
Acclaimed Contributor

Re: problem after rm -rf *

>Bill: The reason for pwd is to show the 'real' directory when using cd in the shell to follow a transition link.

No need to do this. Just use a real shell. A real shell has "pwd -P" to give you the physical path. Of course the default is "pwd -L".

>prasadshete: Bill i was just wondering to know what is
>The "chmod -R 777 *" club
>The "chown -R root:bin *" Club

Well, you don't want to join these clubs.
But since you're paid up member of the rm -rf club, you can get a very cut rate membership, provided you do it BEFORE you restore you broken system. :-)

>Yogeeraj: Nothing to worry about. It was just a joke!

It isn't a joke if you join the club.
Basically don't do those commands.
Heironimus
Honored Contributor

Re: problem after rm -rf *

The problem with aliasing things to use "-i" is that it leads people to habitually use "-f". In particular, "rm -rf" becomes the One True Way to delete anything. I always cringe a little inside as I watch otherwise-good admins use "rm -rf something*" when they specifically want to remove normal files.
James R. Ferguson
Acclaimed Contributor

Re: problem after rm -rf *

Hi (again):

> Heironimus: The problem with aliasing things to use "-i" is that it leads people to habitually use "-f".

As one who *prefers* to alias 'rm' to 'rm -i', I understand your comment. _However_, I look at the requirement to answer the prompt as a nice "are your sure?" that makes me think a fraction of a second before I commit.

If I have several files to remove, and I _do_ want to avoid the interactive prompts, I don't have any problem typing a few more characters to yield:

# /usr/bin/rm file1 file2 file3 ...

...which circumvents the interaction.

Regards!

...JRF...

Heironimus
Honored Contributor

Re: problem after rm -rf *

When I say "habitually" I mean they typed "rm -rf" every time they removed anything as any user, even when using accounts or machines that didn't have the alias set, and always without thinking. In doing so, they bypassed the friendly "are you sure" confirmations and "can not remove directory" errors.
Dennis Handly
Acclaimed Contributor

Re: problem after rm -rf *

>ME: Well, you don't want to join these clubs.

I just thought of one way to do these normally dangerous experiments. Set up a chroot(1m).
After you have hosed yourself a few times, just "exit" back to the real world.