uncompress/compress a whole folder in UNIX

Posted on 2005-03-21
Medium Priority
Last Modified: 2008-02-01
Hi, Can anybody show me how to uncompress/compress a whole folder?  The folder structures should remain the same and only the files are uncompressed/compressed.  Thanks.

Question by:DavidLearns
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 11

Expert Comment

ID: 13594981
Hi DavidLearns,

Why don't you use gzip -r?

Another option would be to 'tar' first and the zip the file


Author Comment

ID: 13595044
Griessh, actually I am trying to uncompress a folder which I believe was compresssed.  And only the files were compressed and folders were not. David
LVL 46

Assisted Solution

by:Kent Olsen
Kent Olsen earned 100 total points
ID: 13595402

Here's a short script that will recursively find all of the compressed files in a directory (and subdirectories) and uncompress them without destroying the original:

find . -name '*.gz' -print | sed 's/^\(.*\)[.]gz$/gunzip < "&" > "\1"/' | sh

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 48

Accepted Solution

Tintin earned 100 total points
ID: 13595413
You can't compress a folder, you can only compress files within a folder (well, let's use Unix terminology here - 'directory').

What compression was used?

If gzip or compress, then do

find /some/dir -name "*.gz" -o -name "*.Z" -exec gzip -d {} \;

If a tar file, do

tar zxvf your.tar.gz

or if your tar command doesn't support the -z flag, do

gzip -dc your.tar.gz | tar xvf -
LVL 11

Expert Comment

ID: 13595583
>> folders were not
a folder can't be compressed, because it is only a structural element. The content of a file however can be compressed.
LVL 11

Expert Comment

ID: 13597111
So, are you saying you have a folder with compressed files ????

Expert Comment

ID: 13642500

to make it generic, you could just say -

$ find /sourcedir/ -name "*" -exec compress {} \;

This would compress any files that it finds in /sourcedir.

LVL 48

Expert Comment

ID: 13647797

What's the point in trying to compress folders, links, devices, FIFO's etc?

Why use compress instead of gzip or bzip2?

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question