RE: major blunders
Date: Thu, 8 Oct 2009 07:51:44 -0400
*Never* use rm -rf ?
I learned that lesson.
I now go to the specific directory. Check twice to make sure I'm there. And simply rm *.log or *.lis or *.trc Then back up a directory and use rmdir directory name.
Rinse and repeat. This takes an extra 10 seconds.
Rm -r is very powerful and way too dangerous for me!
From: oracle-l-bounce_at_freelists.org [mailto:oracle-l-bounce_at_freelists.org] On Behalf Of Jared Still
Sent: Wednesday, October 07, 2009 3:04 PM
Subject: Re: major blunders
On Wed, Oct 7, 2009 at 8:41 AM, April Sims <sims_at_suu.edu<mailto:sims_at_suu.edu>> wrote: Compiling a list of major blunders to avoid:
Don't use the number 8 for scripting or ORACLE_SID due to the wild card character * above it. Don't use rm *.*
Here's a subtle variation on that.
Say you wish to delete all *.lis files in a directory.
The command would be "rm -f *.lis"
The problem with the *. combination is that the * requires using the Shift key, and the . does not require the shift key.
So, if your finger drags a little too long on the shift key, you end up with this:
rm -f *>lis
Can you guess what happens?
Yes, you now have an directory with one empty file named "lis".
A lesson learned long ago, and you can probably guess how I learned it.
Fortunately, this lesson was learned well after the lesson on having good backups available...
Another thing I make use of when running potentially dangerous commands such as rm: use ls first.
Want to see what will be removed by rm -f *.txt?
First run ls *.txt
Then use command history and edit the command you just ran. This way you know the file specification is correct.
Same for shell scripts written to do mass maintenance.
Run it in 'dry run' mode before doing it for real.
for f in $( find . -name "stuff_i_do_not_want") do
ls -ld $f
# uncomment the rm when you are sure it is correct
# rm $f