How to recursively unzip all files in their existing directoies and remove the orginals

So, I am trying to restore a Newznab installation by importing in all my NZBs from my previous installation. Except during the import, all your NZBs need to be unzipped/decompressed and not in a ".nzb.gz" format.
Well I needed to figure out a way to unzip the compressed NZBs into their existing directories and also removing the original compressed NZB (mainly, to save hard drive space). Thankfully after a little research I was able to put together the following command that would accomplish this.
[crayon attributes]
find . -name "*.gz" | xargs gunzip
In the end, this command just recursively searches your working directory for any ".gz" files and decompresses them in their current directory and lastly... removes the original compressed ".gz" file.


  1. Erik Cass says:

    find also has the --exec option which would eliminate the pipe, and is functionally equivalent:

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

    Also, as I recall, you should also use the -0 option with xargs when paired with find due the potential that find can pass a space, which can break xargs. Find's -exec is not subject to this. The -type f option will restrict find to files only as a precaution.

    • crosseye says:

      That's a great alternative Erik, I just looked it up and that's definitely a much cleaner approach. Only thing is that the current command would not recursively scan the sub-directories like I needed but with a backslash before the file extension fixes that problem.
      [crayon attributes]
      find -name \*.gz -type f -exec gunzip {} \;
      I still think though that there should be a period after find but after some testing, both commands produced the same results.
      [crayon attributes]
      find . -name \*.gz -type f -exec gunzip {} \;

  2. says:

    Everyone loves it when people come together and share
    views. Great blog, continue the good work!

  3. a says:

    Thanks in favor of sharing such a pleasant thought,
    article is pleasant, thats why i have read it fully


Leave a Comment

  • Info

    I typically try and keep the blog up-to-date but apparently I'm not very good at posting!