about "rm -rf *" command !
Dear Friends ,
Sometimes we linux person make a command "rm -rf * " which is very dangerous for the Llnux server . By mistake , using the above command I have deleted more importent files . So that I need a suggestion , Is there any way to block the above command or there are any way to make a warning when I give the command : "rm -rf * " Plz suggest me ... |
don't give -f option
|
Write a wrapper script that confirms if using -rf.
|
Hi,
You could alias rm to include the -i (interactive) option: alias rm='rm -i' (to be added to for example your /etc/profile). This will ask you to delete a file (interactive => rm will ask permission before removing anything). I'm not sure if this is workable (you need to say y for every file that needs to be deleted). Being careful and checking what you typed before hitting enter is probably the best way. Anyway, hope this helps. |
to be extra safe how about aliasing "rm -rf" itself to "rm -ri".
but as druuna said the to be prompted every time is surely no fun. |
to be extra safe how about aliasing "rm -rf" itself to "rm -ri".
but as druuna said the to be prompted every time is surely no fun. |
How to protect form "rm -rf * " command
Thx bsat and u r correct that (alias 'rm -rf'='rm -ri' ) is not working . Is there any way to solve it ?
|
about rm -rf * command !
Thx smeezekitty ..
Would u plz help me to write a wrapper script about the above problem ? |
Another alternative is to place a file '-i' in the critical directories.
Code:
touch ./-i Cheers, Tink |
I thought the -f overrides the -i flag?
I would suggest writing a wrapper just as smeezekitty suggested. This doesn't need to be too complex, but you need to work out what you want to cater for. Do you just want to check for -rf or do you want to check anything that includes the -f option? Code:
#!/bin/bash EDIT: aliased would be safer than modifying the PATH! Obviously you can put a lot more testing in the script until you are completely satisfied, for example the -rf option could be reversed to -fr but would have the same impact... |
Quote:
on the command-line wins (which would be -i) The greatest caveat with the file method is that it only protects files that start with character that's lower in the sort order than the '-' .... Cheers, Tink |
rm -rf solution is to use -I
if you want to protect yourself, I guess the best bet is to alias rm to use -I like below:
alias rm="rm -I" This would ensure that if there are more than three files to be deleted then only rm will confirm. |
@raj77_in: That should be i instead of I. Which was already contributed by several people.....
|
All times are GMT -5. The time now is 03:50 PM. |