Undo a shell script when input file is overwritten
3
0
Entering edit mode
5.6 years ago
rse ▴ 100

Hi,

Is it possible to redo a shell script? I overwrote my files running a shell script

I ran nohup sh 1.sh
But my output file was same as the input file, so it overwrote my input file

Thank you

next-gen • 2.0k views
ADD COMMENT
0
Entering edit mode

Changed the title to make it more specific, added the additional information provided in the comments to the original question, cleaned up comments, and moved comments to answer so you can mark them as accepted.

ADD REPLY
0
Entering edit mode

Thank you for your help. I don't have backup of file but i am still optimistic. I used zcat and gzip to merge and zip the files using : zcat file1.fastq.gz file2.fastq.gz | gzip -c > file1.fastq.gz

ADD REPLY
2
Entering edit mode

You could just do cat file1.fastq.gz file2.fastq.gz > merged.fastq.gz. There is no need to zcat/gzip again.

ADD REPLY
0
Entering edit mode

zcat already concatanates compressed files, there is no need for gzip in this command:

zcat file1.fastq.gz file2.fastq.gz > file1.fastq.gz
ADD REPLY
0
Entering edit mode

Ok, thanks. But my file1.gz is empty now

ADD REPLY
0
Entering edit mode
ADD REPLY
0
Entering edit mode

Sorry, did not pay attention. Use cat to concatenate:

cat file1.fastq.gz file2.fastq.gz > new.fastq.gz

Also do not write to a file with identical name as the input.

ADD REPLY
0
Entering edit mode
5.6 years ago
Carambakaracho ★ 3.3k
  • restore input from backup
  • recompute input

there's not much else you can do... sooner or later, that happens to everybody

ADD COMMENT
2
Entering edit mode
rm * .bam
ADD REPLY
0
Entering edit mode

Lol...don't want to delete more files

ADD REPLY
0
Entering edit mode
5.6 years ago

Your input file is gone. Unless you have a backup somewhere, there is no way to restore it or "redo" the script.

Pro tip: make sure your input files are read-only (chmod -w) to avoid loss of data.

ADD COMMENT
0
Entering edit mode

You mean chmod -w, no?

ADD REPLY
0
Entering edit mode

Certainly! Will change my post.

ADD REPLY
0
Entering edit mode
5.6 years ago
Joe 21k

As others have said, your data is long gone, unless:

  • You have the original input data, and can simply recompute it easily enough.
  • Your server/SysAdmin has configured regular snapshots, but this isn't that common, and would probably only get you to whereever you were yesterday.

There's no such thing as a recycle bin on Unix, so when you delete stuff - you really delete stuff.

ADD COMMENT

Login before adding your answer.

Traffic: 2487 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6