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.

When I right-click a file in Mac OSX and select "Compress 'File Name'", what is the equivalent bash or terminal command to get the same result?

Is it just gzip -9 /path/to/filename?

share|improve this question

migrated from stackoverflow.com Mar 29 '13 at 0:50

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

add comment

3 Answers

gzip is a different, incompatible algorithm. It's better compression, and not encumbered by any patents, but it's only supported out of the box on Unix and Unix-like systems (including Linux and OSX, but not Windows). What you're looking for is zip. OSX ships with that as a command-line utility too. See man zip for options.

share|improve this answer
    
+1 Not encumbered by any patents, nice. –  squiguy Mar 28 '13 at 22:32
    
The command-line zip (and the Compress menu item) use the same compression method as gzip, i.e. deflate. The "better compression" you're thinking of could only be with respect to compressing a tar file as one thing with gzip, as opposed to the zip approach of compressing each file individually. In any case, both gzip and Info-ZIP zip are not encumbered by any patents. –  Mark Adler Mar 29 '13 at 0:15
add comment
ditto -ck --rsrc --sequesterRsrc --keepParent folder folder.zip

ditto -ck uses Info-ZIP's zip.

share|improve this answer
add comment

If you 'Compress' a directory/folder called myDir, or something like that, then you get the equivalent of

% zip -r myDir.zip myDir

If you 'Compress' a single file, f1, then you get something like

% zip -r f1.zip f1

This is Info-ZIP; there's a long and painful story about Info-ZIP vs PKZIP, which has patents and personalia aplenty. As far as I'm aware, Info-ZIP is unencumbered.

You can unpack Zip archives with unzip, and list their contents with unzip -l.

Just by the way, one important difference between Zip and gzip is that Zip is both an archiver and a compressor, whereas gzip is designed only to compress single files. The files that gzip compresses might be archive files (most commonly tar files), but the two jobs are separate. If you want really good compression, then bzip2 (see the man page) is reported to be more effective even than gzip -9.

share|improve this answer
1  
The zip command doesn't include anything beyond basic file metadata in the archive, while the Finder includes them using the AppleDouble format. To include the metadata, use ditto instead (see @Mark Adler's answer). –  Gordon Davisson Mar 29 '13 at 1:26
    
Ahaaa: thank you. I was sure there had to be some difference; I should have thought of looking at ditto. It's good to know that the difference concerns only AppleDouble and resources. –  Norman Gray Mar 29 '13 at 10:16
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.