LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   tips to avoid rm mistakes (https://www.linuxquestions.org/questions/linux-newbie-8/tips-to-avoid-rm-mistakes-134960/)

statmobile 01-14-2004 11:41 PM

tips to avoid rm mistakes
 
Hey experts,
I'm looking for a little input on dealing with any
Code:

rm filename
or worse yet,
Code:

rm -r filename
mistakes. Do you have anything setup on your system, so that you can avoid any enormous disasters? I absolutely love Linux, but this is something that scares me. It's so easy, especially wiith tabbing, to accidentally remove a file. I'm a creature of habit, where I often just go through the routine, before taking the time to read through my commands. It's poor practice, I know, but I'm just looking for some advice from the gurus in LQ land.

Thanks!

P.S. Maybe even some tips on how to deal with a mistake that may have already happened as well.

P.P.S. "Don't be stupid, and think before you hit Enter" Does not count as a tip, although it is very good advice. :D

PbO 01-14-2004 11:54 PM

put alias rm='rm -i' in your .profile

This forces you to confirm each delete.

quatsch 01-14-2004 11:55 PM

above and don't ever use the
-f
option.

megaspaz 01-14-2004 11:56 PM

well redhat aliases the rm command to use rm -i which will prompt you if you really want to delete a file. just be careful with the -f flag as that will just delete anything without prompting you. also be careful with your spelling when deleting files whose filepaths start with "/". don't mistakenly put spaces in those kind of file paths. also be careful with the wildcard character, "*".

statmobile 01-15-2004 12:14 AM

Nobody uses the technique of keeping a "trash" directory. How writing a script that puts it into this directory, and then another script that deletes all files that are over 7 days old?

I once read a forum discussion on the repercussions of changing the rm command, and this is something that would need to be kept in mind.

Those tips are very useful, but I'm looking for something to protect me a little more. For instance, if I have to put a "yes" in every time I try to remove a file, then that will again be part of my regular routine. I make mistakes often, or make multiple files for backup, thus removing is a vital command in my library.

If I'm just being difficult here, then you should tell me. I was just wondering if there is any special approach that some of you gurus use.

megaspaz 01-15-2004 12:18 AM

you're being difficult. :p

really, though, if you're prompted if you want to delete a file, you shouldn't be giving it a cursory gloss over. you really need to think if the file you're going to delete is going to break something. in the gui, that's what the trash icon is for. so you can reverse a "delete" if you change your mind. in the shell that's what the -i is for. only really delete a file if you're pretty sure it's not a necessary file.


All times are GMT -5. The time now is 02:06 PM.