View previous topic :: View next topic |
Author |
Message |
BillyD Guru
Joined: 05 May 2002 Posts: 323 Location: Australia
|
Posted: Sat Dec 28, 2002 12:35 am Post subject: Minimize the risk of accidental deletions |
|
|
I guess this will be old news to many, but after reading a few posts asking for advice after accidentally deleting files, and doing it myself a couple of times, I thought I would include a tip for those that wish idiot proof their boxes a little more but are unsure how.
Adding the following code to your .profile gives you a few options when using the all powerful rm command.
will ask you a yes or no question before the file(s) is actually deleted, giving you a second or two to think it over.
This can be annoying when you a deleting in bulk, so you can add another alias for the times when you are going to be getting rid of a lot of files:
which will not prompt you for a confirmation. _________________ We used to have hominid cousins that were vegetarian. The palæontological record suggests that our ancestors killed them and ate them. |
|
Back to top |
|
|
proxy Apprentice
Joined: 20 Apr 2002 Posts: 260 Location: Chantilly, VA
|
Posted: Sat Dec 28, 2002 8:42 am Post subject: |
|
|
actually the -f flag overrides the -i flag...so what normally do (and have come to expect on the systems i have setup) is alias rm to rm -i and what i want to do a mass deltion i just type "rm -f" which is effectivly "rm -i -f"...which of course doesnt ask
so by it self the alias is very intuative.
proxy |
|
Back to top |
|
|
meowsqueak Veteran
Joined: 26 Aug 2003 Posts: 1549 Location: New Zealand
|
Posted: Thu Aug 28, 2003 5:36 am Post subject: |
|
|
After reading through some old posts in the forum today, I came across this handy hint:
If you create a file called '-i' in your home directory as such:
if you are ever in ~ and accidentally type 'rm *' with any options (which makes it a bit more flexible than the aliases above) then the shell will expand it out to 'rm file1 file2 ... -i' which rm will interpret as being the -i option.
This is useful if you ever accidentally add a space to the command, for example:
Code: | localhost [~] $ rm -r -f src/ * |
Oops! This hint might just save your home directory in this situation! |
|
Back to top |
|
|
Kodama Tux's lil' helper
Joined: 28 Jan 2003 Posts: 85 Location: Linköping, Sweden
|
Posted: Fri Aug 29, 2003 5:39 pm Post subject: |
|
|
Here's a tip that have saved my life a few times.
Code: | alias rm='remove'
alias emptytrash='"rm" -r /trash/*'
remove()
{
mv "$1" /trash
} |
|
|
Back to top |
|
|
koala Tux's lil' helper
Joined: 15 Aug 2002 Posts: 91 Location: Barcelona, Spain
|
Posted: Fri Aug 29, 2003 7:04 pm Post subject: |
|
|
meowsqueak wrote: | After reading through some old posts in the forum today, I came across this handy hint:
If you create a file called '-i' in your home directory as such:
if you are ever in ~ and accidentally type 'rm *' with any options (which makes it a bit more flexible than the aliases above) then the shell will expand it out to 'rm file1 file2 ... -i' which rm will interpret as being the -i option.
This is useful if you ever accidentally add a space to the command, for example:
Code: | localhost [~] $ rm -r -f src/ * |
Oops! This hint might just save your home directory in this situation! |
are you sure you know what does the -i option do in all commands you might execute? |
|
Back to top |
|
|
meowsqueak Veteran
Joined: 26 Aug 2003 Posts: 1549 Location: New Zealand
|
Posted: Sat Aug 30, 2003 1:29 am Post subject: Good point |
|
|
Yeah, you make a very good point. If I'd thought about this a bit more I would have realised that too. As such, I have removed this 'helpful' little file...
Which leads to an interesting thought - what sorts of filenames can you create that cause trouble? I read somewhere about putting a special filename somewhere so that doing a 'find | xargs rm' ended up removing the root directory. You should use this instead:
Code: | $ find ... -print0 | xargs -0 ... |
This handles annoying files with spaces in them too. |
|
Back to top |
|
|
|