How do I gunzip all files recursively in a target directory?

gunzip has -r option. From man gunzip :

   -r --recursive
          Travel  the directory structure recursively. If any of the 
file names specified on the command line are directories, gzip 
will descend into the directory and compress all the files it finds
there (or decompress them in  the  case  of gunzip ).

So, if you want to gunzip all compressed files (gunzip can currently decompress files created by gzip, zip, compress, compress -H or pack) inside the directory /foo/bar and all its subdirectories :

gunzip -r /foo/bar

This will handle file names with spaces too.


Using the commands below. Replace <path_of_your_zips> with the path to your ZIP files and <out> with your destination folder:

  • For GZ files

    find <path_of_your_zips> -type f -name "*.gz" -exec tar xf {} -C <out> \;
    

    or

    find <path_of_your_zips> -type f -name "*.gz" -print0 | xargs -0 -I{} tar xf {} -C <out>
    
  • For ZIP files

    find <path_of_your_zips> -type f -name "*.zip" -exec unzip {} -d <out> \;
    

    or

    find <path_of_your_zips> -type f -name "*.zip" -print0 | xargs -0 -I{} unzip {} -d <out>
    

Tags:

Gzip

Extract