Skip to main content

How can I uncompress gz files in random directories and store the decompressed files in those same directories?

CentOS 5.9

I've got a server with a foo.ext.gz file located in a variety of random directories.

Example:

/opt/fooapp/foosubdirectory/foo_<randomnumber>/blah/blah/foo.ext.gz /opt/fooapp/foosubdirectory/foo_<differentrandomnumber>/blah/blah/foo.ext.gz /opt/fooapp/foosubdirectory/foo_<anotherdifferentrandomnumber>/blah/blah/foo.ext.gz 

I'd like to run a bash command that will:

  1. Locate foo.ext.gz files
  2. Extract the contents of the gz file in the same directory that its respective GZ file resides in
  3. Keep the original gz file intact.

If I was doing this manually, I'd start with find / -iname foot.ext.gz. After that, I'd copy the directory the file resides in and type something like:

gunzip -c /opt/fooapp/foosubdirectory/foo_12345/blah/blah/foo.ext.gz > /opt/fooapp/foosubdirectory/foo_12345/blah/blah/foo.ext 

The problem here is that I need to manually do this process for several dozen files/directories.

Is there a way I can leverage xargs or a for loop?

Any thoughts?

Mike B
  • 9.2k
  • 25
  • 75
  • 98