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 want to do an ordinary "zip", so my CW3 file becomes CW3.zip. I have tried to use some example commands found on the internet but they don't seem to work.

I have tried the following, resulting in the error below:

$ zip CW3
zip error: Nothing to do! (CW3.zip)

I also tried:

compress -If CW3

Bottomline: how do I compress a file in UNIX?

share|improve this question

migrated from stackoverflow.com Mar 31 '11 at 17:20

This question came from our site for professional and enthusiast programmers.

    
Post what you have tried and why it's failing (e.g. error messages). –  Bleaourgh Mar 31 '11 at 16:55
    
Is zip package installed? zip are uncommon on *nixes as they use more often tar derivatives (i.e. tar+gz tar+bzip2 and increasingly tar+xz). –  Maciej Piechotka Mar 31 '11 at 17:00
    
@Macej: I think it's installed correctly, "Nothing to do!" is an usual zip output. –  schnaader Mar 31 '11 at 17:02
    
Not a programming question, I suspect. A Unix command question. Wrong site. –  Tom Zych Mar 31 '11 at 17:06

3 Answers 3

zip syntax is

zip archivefile1 file1 file2 file3

for compression,

unzip archivefile1

for decompression.

So in your case, for compression:

zip CW3.zip CW3

See here.

share|improve this answer

If you are flexible about the format, you can compress a file in Unix doing just that :-)

 compress some_file

downside: you need to specify every single file to compress.

You can also use zip, not always available on UNIX platforms, or gzip. While compress and gzip just compress a single file, zip is a tool that handles packaging of one or many files or directories and compression all in one go. The traditional UNIX philosophy is to have one tool for one job, making it easier for the tool's creator to make the tool excel at that one job, explaining why compress and gzip only compress, and do not package. For you as a user that means you will use use one tool for packaging, and then another to compress the package (or "archive"), if you are not using zip, but UNIX native tar, the tape archiver, to package first:

tar -c -f archive_name.tar some_file some_dir

will pack some_file and some_dir, recursively, in the archive archive_name.tar.

now compress it:

gzip archive_name.tar

will give you the compressed file archive_name.tar.gz (and delete the original archive_name.tar).

But wait, there is more: it is actually so common to compress archives, that tar can call gzip, in one command:

tar -c -z -f archive_name.tar.gz some_file some_dir

will give you archive_name.tar.gz, containing some_file and some_dir, packaged recursively, and compressed.

For more info:

man 1 tar
share|improve this answer
    
man, if you actually spend time making taste judgements about my utterings, why not fix the typos, too... –  Florenz Kley Dec 15 '11 at 22:25

zip is usually not installed by default. It is more of an archiving tool than a single file compression tool.

Either gzip or compress should be installed. They are files compression tools which add a .gz or .Z extension to the compressed file. The bzip2 program may also be installed.

gzip and bzip2 are usually install with a suite of programs to cat, diff, or grep files. These would be zcat, zdiff, and zgrep or bzcat, bzdiff, and bzgrep respectively.

share|improve this answer

Your Answer

 
discard

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