Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I've been unable to compress the contents of a folder on Unix, note that I don't want to compress the directory itself but the contents inside.

so far.. to compresss the files I use:

compress /serv/test/file.sas7dbt

Lets say I want to compress all files in the folder test, how can I achieve this?

share|improve this question
    
Do you need to use compress or would tar -cZ work? –  Martin Samson Oct 31 '11 at 19:59
    
Consider carefully whether you really want to use compress. That's a very old compression program (it produces .Z files, if that refreshes anyone's memory). Typical Linux systems don't even have it, though I think gzip can uncompress compressed files. Newer and better compression programs include gzip and bzip2. –  Keith Thompson Nov 22 '11 at 1:42
add comment

1 Answer

up vote 0 down vote accepted

If you can use bzip2:

for file in /serv/test/*; do
    bzip2 -k $file
done

The -k option keeps the original file.

With compress, the loop would be really close.

If you can use tar, it will create a single file archive instead of multiple files.

EDIT: as gman pointed out, the find utility can be used to compress instead of doing a for loop:

find /serv/test/ -type f -exec bzip2 -k {} \;
share|improve this answer
    
It's really only compressing files separately that is the key. You could also use a find /path/ -type f -exec bzip2 .... to achieve the same result. You can also use the compression utility of your choice: zip/gzip/etc. –  Garrett Oct 31 '11 at 21:20
    
Yup, forgot about find :) –  Martin Samson Oct 31 '11 at 21:26
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.