Holy SH!!! Accidentally "rm script.sh" instead of script.txt
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Mostly RedHat. Also Suse, Ubuntu, PHLAK etc.
Posts: 149
Original Poster
Rep:
Thanks all for replying. Unfortunately I found myself with my heart sunk into my shoes... The script was built following the advice from numerous threads, the code I used isn't in the threads itself.
What really P.O.ed me was that the system didn't even do a confirmation, it just deleted it from the word go, or in this case the word "rm".
But not to be punched out, I've already started rebuilding it, it's now at about 50%. It's faster, smaller and more effective than the old one was so far, uses fewer external scripts and is generally just darn better!
So take that, rm!
Speak to you all again later when the script is at 100%.
Well, it assumes you know what you want when you type it. They say Linux is for gurus and we are not supposed to have someone, like Billy boy, hold our hands.
Don't feel to bad, I once did a rm -rf /* and that was fun. Since I didn't use the -v option I didn't realize what I did until it stopped. It stopped when it got almost done with /sbin. Then it complained about a missing file. Yup, I did a reinstall of Gentoo.
It could be worse. At least your new script is faster.
Distribution: Mostly RedHat. Also Suse, Ubuntu, PHLAK etc.
Posts: 149
Original Poster
Rep:
"They say Linux is for gurus..." <- I agree, but even gurus suffer from absent-mindedness. In fact, I think gurus probably suffer more from absent-mindedness than anyone else!
Anyway, why does it ask for confirmation when logged in as root, but not when logged in as a normal Joe-Schmoe user?
That's just messed up!
It also illustrates my point = The root user is probably the "guru" who is absent-minded, the OS better ask him/ her if he/ she is absolutely sure they want to rm this file. The average user is probably an accountant or a lawyer who suffers from tunnel-vision-thinking, no need to ask them since they probably don't know what the hell they're doing anyway!
In my case the "guru" logged into a normal user account without receiving the "guru-benefits" associated with root!
Haha! I'm just yanking a few laughs out of my predicament now. Anyway, thanks all.
Distribution: Mostly RedHat. Also Suse, Ubuntu, PHLAK etc.
Posts: 149
Original Poster
Rep:
Quote:
Originally Posted by Simon Bridge
It will assume the superuser has authority to do everything - you are always strongly warned about doing anything as root. As a regular user you get:
Code:
[~]$ rm doomed-file.txt
rm: remove regular file `doomed-file.txt'? y
[~]$
... for example.
Your experience is one of the many reasones you keep hearing that you should not log in as root and be very wary of anything you do as root.
That's just it though. I DID get "rm: remove regular file blabla..." when i WAS logged in as root.
I DID NOT get this when I was logged in as a normal user... The rm command was performed from $, not #.
Not that it matters now, my script is at 100% completion and it's working great! Thanks for all who assisted me (and I needed a whole lot of assisting! )
Quote:
Originally Posted by Genesee
easy to prevent that - just alias rm to "rm -i" in a config file.
also do the same for mv and cp while you're at it....
Thanks friend, I think I will do that in case I rm the wrong file again, which is a very high probability!
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
Well, no matter how stupid it may seem, the same thing happened to me yesterday.
I had been working on a script (and some auxiliary gnuplot and awk programs) for 2 weeks. I was finished, and wanted to do everything real nice, and cleaned up the copied and temporary files I had created. So I added that to my script.
Code:
for fname in "$file1" "$file2"
do
rm fname.*
done
Uhm, I developed this script in the same directory as were my data files were. Not smart. Because after I executed this part EVERYTHING was wiped out in the directory. Including my scripts!
What happened was that $file2 had not been assigned a value. (a typo somewhere) So what was executed was:
Code:
rm .*
Which wiped out everything. :-(
FORTUNATELY I had the main script file open in an editor, and I could recover most of the contents of other files thru scrolling back the terminal buffer, but boy, I was scared!
To avoid this in the future I added this small test:
Code:
if [ "$fname" != ""]
then
rm "$fname".*
fi
Oh, and use another directory for scripting and files.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.