LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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


Reply
  Search this Thread
Old 04-01-2006, 12:19 AM   #1
kinetik
Member
 
Registered: Dec 2005
Location: The most beautiful city in the world.
Distribution: Mostly RedHat. Also Suse, Ubuntu, PHLAK etc.
Posts: 149

Rep: Reputation: 15
Unhappy 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...
 
Old 04-01-2006, 01:35 AM   #2
UltimaGuy
Member
 
Registered: Aug 2003
Location: Chennai, India
Distribution: PCLinuxOS .92, FC4
Posts: 840

Rep: Reputation: 32
If you have done an rm it is not recoverable !!!
 
Old 04-01-2006, 01:53 AM   #3
dalek
Senior Member
 
Registered: Jul 2003
Location: Mississippi USA
Distribution: Gentoo
Posts: 2,058
Blog Entries: 2

Rep: Reputation: 79
kinetik, you are floored. Data recovery is your only option now. Best of luck.

Later

 
Old 04-01-2006, 02:51 AM   #4
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
You have to grep through the partition it was stored on. There are threads on this...
 
Old 04-01-2006, 03:15 AM   #5
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
http://www.linuxquestions.org/questi...d.php?t=428962
http://www.linuxquestions.org/questi...grep+partition

Since the file you want is just a text file, the data you want will be obvious.

grep -a --colour -A3 -B1 /dev/<partition> <some text you know is in the file you want to find>
 
Old 04-01-2006, 08:48 AM   #6
comptiger5000
Member
 
Registered: May 2005
Distribution: Fedora Core Since version 3
Posts: 193

Rep: Reputation: 30
what filesystem are you using?

if its ext3, its gonna be tough
 
Old 04-01-2006, 08:59 AM   #7
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 234Reputation: 234Reputation: 234
I assume that going back to the forum/thread where it was delveloped won't work.
 
Old 04-01-2006, 01:27 PM   #8
kinetik
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: Reputation: 15
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%.
 
Old 04-01-2006, 01:55 PM   #9
dalek
Senior Member
 
Registered: Jul 2003
Location: Mississippi USA
Distribution: Gentoo
Posts: 2,058
Blog Entries: 2

Rep: Reputation: 79
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.

 
Old 04-01-2006, 03:37 PM   #10
kinetik
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: Reputation: 15
"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.
 
Old 04-01-2006, 04:25 PM   #11
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,467

Rep: Reputation: Disabled
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.
 
Old 04-01-2006, 08:33 PM   #12
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
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.
 
Old 04-01-2006, 09:00 PM   #13
Genesee
Member
 
Registered: Dec 2002
Distribution: Slackware
Posts: 927

Rep: Reputation: 30
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 09:02 PM.
 
Old 04-01-2006, 09:41 PM   #14
kinetik
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: Reputation: 15
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 09:43 PM.
 
Old 04-04-2006, 06:08 PM   #15
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
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.

jlinkels
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 7 12-19-2015 02:03 AM
Shell Script: Find "Word" Run "Command" granatica Linux - Software 5 07-25-2007 08:42 AM
How to write a bash script to replace all "KH" to "K" in file ABC??? cqmyg5 Slackware 4 07-24-2007 10:00 AM
Can't install "glibmm" library. "configure" script can't find "sigc++-2.0&q kornerr Linux - General 4 05-10-2005 03:32 PM
Monthly Archiving Script... help with "date" & "cron" Supp0rtLinux Linux - Software 3 01-03-2003 10:29 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration