Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 Mar 29 '13 at 0:50

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

ditto -ck --rsrc --sequesterRsrc --keepParent folder

ditto -ck uses Info-ZIP's zip.

share|improve this answer

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

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

% zip -r myDir

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

% zip -r 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
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .