I've trashed my system with gzip

Asked by LEGOManiac

I was trying to copy my son's profile from one machine to another my plan was to zip his profile then use sftp to transfer it to another computer and unzip it there.

Here's what I did:

in the Home directory as root:

gzip -c -r -f alexander

My expectation was that this would create a file alexander.gz and work recursively through his sub-directories to gather all the files.

I realize after the fact that I should have used ./alexander and I suspect that's where I went wrong, although I'm surprised it didn't just complain that no such file existed.

At any rate, it has now gzipped all my filles in all the subdirectories (at least until such point as the system crashed)

I can't reboot it (surprise, surprise) so I've used the 10.10 installation disk to start a session.

I used the find command to create a listing of all the files, with paths, that contain .gz files that were crated today and store them in a file.

My plan was to simply edit the file, and use global search/replace to insert "gzip -d " in front of each directory listing.

Heres a sample of what I now have:

gzip -d /media/3d120cdc-c938-4e1c-adc1-2549693a9b77/vmlinuz.gz
gzip -d /media/3d120cdc-c938-4e1c-adc1-2549693a9b77/tmp/operaprint.ps.gz
gzip -d /media/3d120cdc-c938-4e1c-adc1-2549693a9b77/tmp/.ktorrent_kde4_1000.lock.gz
gzip -d /media/3d120cdc-c938-4e1c-adc1-2549693a9b77/tmp/pulse-Uw7AF7K4xafu/pid.gz
gzip -d /media/3d120cdc-c938-4e1c-adc1-2549693a9b77/tmp/.X1-lock.gz
gzip -d /media/3d120cdc-c938-4e1c-adc1-2549693a9b77/tmp/.wine-1000/server-801-b00fc1/lock.gz

The batch file is executable, but when I run it, every single line reports that the file is not found, yet, when I cut and paste a single line in to a terminal, it unzips the individual file.

I can't figure out why this isn't working. Can anyone tell me what I'm doing wrong?

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu gzip Edit question
Assignee:
No assignee Edit question
Solved by:
mycae
Solved:
Last query:
Last reply:
Revision history for this message
Best mycae (mycae) said :
#1

Try using find's "exec" command.

for example

find ./ -name \*.gz -exec gunzip {} \;

The {} substitutes the name of the file.

Revision history for this message
LEGOManiac (bzflaglegomaniac) said :
#2

Thanks, mycae, that appears to have solved the problem.

I had tried the -exec option but wasn't aware of the {} symbols, nor the requirement for a trailing "\ ;" so it didn't work for me when I tried it myself. Thanks for clarifying.

I'll close the question in a day or so, but I'd appreciate it if someone could address the problem of why my gzip lines don't work in a script but do work when run individually. I don't understand that. I thought anything that worked from a command line could be put in a script.

Revision history for this message
LEGOManiac (bzflaglegomaniac) said :
#3

Thanks mycae, that solved my question.