How to create the zip same as Finder creates, from the terminal or the shell script

CLI

Finder has a function create the zip file from the file or the folder. This zip file is different from the zip file Windows creates. This article says this zip file as Finder style zip file.

You can create this zip file from the terminal and the shell script. You can create it in the automated script.

This article explains that how to create the Finder style zip file and how to expand it.

スポンサーリンク

Creating the Finder style zip file

You can create the Finder style zip file with ditto.

$ ditto -c -k --sequesterRsrc --keepParent Test Test.zip

Above line create the Test.zip file by archiving the Test folder.

-c option specify creates the archive, -k option specify compress with PKZip, --sequesterRsrc option create the __MACOSX folder to store the resource fork and the HFS meta data.

Specify only one file

If you create the zip file with only one file, --keepParent option may be an obstacle. For example, following line create the zip file by archiving the 123.jpg file in the desktop.

$ ditto -c -k --sequesterRsrc --keepParent 123.jpg 123.zip

Expand it, the Desktop folder will be created and the 123.jpg file is put in the created folder. Redundant folder will be created.

--keepParent option put the Desktop folder which is a parent folder of the 123.jpg file.

It may be better to create without --keepParent option if you create the zip file with only one file.

However, this is not good with the application package. The application package is looked like a simple file in the Finder, but it is a folder. The --keepParent option is need to archive the application package.

Expanding the zip file

The ditto can expand the zip file. Following line expand the Finder style zip file:

$ ditto -x -k TextEdit.zip ./

Above line expand the TextEdit.zip file into the current directory. If you replace ./ with the destination folder, ditto will create the destination folder and expand into it.

The -x option expand the archive, and the -k option indicate that the format of the zip file is the PKZip format.

スポンサーリンク
最新情報をチェックしよう!
>現役のプログラマーが書くプログラミング情報

現役のプログラマーが書くプログラミング情報

日々の開発の中での学びや分かったこと、調べたことなどを書いていくブログです。

CTR IMG