Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Minimize the risk of accidental deletions
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
BillyD
Guru
Guru


Joined: 05 May 2002
Posts: 323
Location: Australia

PostPosted: Sat Dec 28, 2002 12:35 am    Post subject: Minimize the risk of accidental deletions Reply with quote

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.

Code:
alias rm="rm -i"

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:

Code:
alias del="rm"


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
View user's profile Send private message
proxy
Apprentice
Apprentice


Joined: 20 Apr 2002
Posts: 260
Location: Chantilly, VA

PostPosted: Sat Dec 28, 2002 8:42 am    Post subject: Reply with quote

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
View user's profile Send private message
meowsqueak
Veteran
Veteran


Joined: 26 Aug 2003
Posts: 1549
Location: New Zealand

PostPosted: Thu Aug 28, 2003 5:36 am    Post subject: Reply with quote

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:
Code:
touch -- -i

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
View user's profile Send private message
Kodama
Tux's lil' helper
Tux's lil' helper


Joined: 28 Jan 2003
Posts: 85
Location: Linköping, Sweden

PostPosted: Fri Aug 29, 2003 5:39 pm    Post subject: Reply with quote

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
View user's profile Send private message
koala
Tux's lil' helper
Tux's lil' helper


Joined: 15 Aug 2002
Posts: 91
Location: Barcelona, Spain

PostPosted: Fri Aug 29, 2003 7:04 pm    Post subject: Reply with quote

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:
Code:
touch -- -i

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
View user's profile Send private message
meowsqueak
Veteran
Veteran


Joined: 26 Aug 2003
Posts: 1549
Location: New Zealand

PostPosted: Sat Aug 30, 2003 1:29 am    Post subject: Good point Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum