Create Finder-equivalent zip archives from the Terminal

Jan 15, '04 09:03:00AM

Contributed by: Anonymous

I absolutely love the "Create Archive of ..." functionality in Panther, found in the Finder's File menu or in the contextual menu when you control-click on an item in the Finder. It's much faster than Stuffit, and it doesn't require me to install any third-party software. Sometimes I need to be able to create archives from the command line, and I wondered how I could get the same functionality of the "Create Archive of ..." function in the terminal. tar and gzip are out because they don't preserve resource forks and HFS metadata.

The answer: the ditto command. After some experimentation, I found that ditto with the following options will create an archive just like the "Create Archive of ..." function:

ditto -c -k -keepParent -rsrc source destination
where source is the file or directory you want to archive and destination is the name you want to give the new archive file. For example, to create an archive of a directory named Foo to a file named Foo.zip, use:
ditto -c -k -keepParent -rsrc Foo Foo.zip
[robg adds: We've covered ditto before, and the above syntax was included in a handy folder action script hint, but I thought it might be worth sharing the command-line version in its own hint.]

Comments (7)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20031223150348992