Linux - Software This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
 |
03-31-2006, 11:19 PM
|
#1
|
Member
Registered: Dec 2005
Location: The most beautiful city in the world.
Distribution: Mostly RedHat. Also Suse, Ubuntu, PHLAK etc.
Posts: 149
Rep:
|
Holy SH!!! Accidentally "rm script.sh" instead of script.txt
Is there any way I can recover a file called script.sh if I did an rm on it?
Please, this was a script built after posting many questions on this forum, I'll be floored if it's gone...
|
|
|
04-01-2006, 12:35 AM
|
#2
|
Member
Registered: Aug 2003
Location: Chennai, India
Distribution: PCLinuxOS .92, FC4
Posts: 840
Rep:
|
If you have done an rm it is not recoverable !!!
|
|
|
04-01-2006, 12:53 AM
|
#3
|
Senior Member
Registered: Jul 2003
Location: Mississippi USA
Distribution: Gentoo
Posts: 2,058
Rep:
|
|
|
|
04-01-2006, 01:51 AM
|
#4
|
LQ Guru
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211
Rep: 
|
You have to grep through the partition it was stored on. There are threads on this...
|
|
|
04-01-2006, 07:48 AM
|
#6
|
Member
Registered: May 2005
Distribution: Fedora Core Since version 3
Posts: 193
Rep:
|
what filesystem are you using?
if its ext3, its gonna be tough
|
|
|
04-01-2006, 07:59 AM
|
#7
|
Senior Member
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
|
I assume that going back to the forum/thread where it was delveloped won't work.
|
|
|
04-01-2006, 12:27 PM
|
#8
|
Member
Registered: Dec 2005
Location: The most beautiful city in the world.
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%. 
|
|
|
04-01-2006, 12:55 PM
|
#9
|
Senior Member
Registered: Jul 2003
Location: Mississippi USA
Distribution: Gentoo
Posts: 2,058
Rep:
|
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.

|
|
|
04-01-2006, 02:37 PM
|
#10
|
Member
Registered: Dec 2005
Location: The most beautiful city in the world.
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.
|
|
|
04-01-2006, 03:25 PM
|
#11
|
Senior Member
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,467
Rep: 
|
Heres something you might find helpful:
mkdir ~/.trash
then make a script called 'can':
#!/bin/bash
mv $1 $HOME/.trash
Put this in your path. Then instead of using 'rm xxx' use 'can xxx' and move files to .trash folder where you can go through them later and delete.
|
|
|
04-01-2006, 07:33 PM
|
#12
|
LQ Guru
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211
Rep: 
|
Quote:
Originally Posted by kinetik
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".
|
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.
|
|
|
04-01-2006, 08:00 PM
|
#13
|
Member
Registered: Dec 2002
Distribution: Slackware
Posts: 927
Rep:
|
Quote:
Originally Posted by kinetik
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!
|
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....
Last edited by Genesee; 04-01-2006 at 08:02 PM.
|
|
|
04-01-2006, 08:41 PM
|
#14
|
Member
Registered: Dec 2005
Location: The most beautiful city in the world.
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! 
Last edited by kinetik; 04-01-2006 at 08:43 PM.
|
|
|
04-04-2006, 05:08 PM
|
#15
|
LQ Guru
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,196
|
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:
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.
jlinkels
|
|
|
All times are GMT -5. The time now is 06:26 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|