?
Solved

uncompress/compress a whole folder in UNIX

Posted on 2005-03-21
8
Medium Priority
?
2,137 Views
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.

David
0
Comment
Question by:DavidLearns
8 Comments
 
LVL 11

Expert Comment

by:griessh
ID: 13594981
Hi DavidLearns,

Why don't you use gzip -r?

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

======
Werner
0
 

Author Comment

by:DavidLearns
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
0
 
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

 
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 48

Accepted Solution

by:
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 -
0
 
LVL 11

Expert Comment

by:griessh
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.
0
 
LVL 11

Expert Comment

by:griessh
ID: 13597111
So, are you saying you have a folder with compressed files ????
0
 
LVL 1

Expert Comment

by:kusuma_hs
ID: 13642500
Hi,

to make it generic, you could just say -

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

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

Regards,
Kusuma
0
 
LVL 48

Expert Comment

by:Tintin
ID: 13647797
kusuma.

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

Why use compress instead of gzip or bzip2?
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

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

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
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

569 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