I erased the written manuscript! Only at that time, I said that I had disabled the local snapshot function ... I thought I should rewrite it while remembering it, but I didn't feel like it. So, I hurriedly replaced it with the content planned for the 31st session. I will write the 30th phantom, when I feel like it. Tohoho.
Well, this time about "zip". It seems that some people are wondering why they are throwing in such worn-out material, but with the momentum of Apple, we recognize that it is a topic that is in demand now that migrants from other platforms are endless. Why don't you wipe out the part of "I thought I understood somehow" at this time?
Meaning of "__MACOSX"
OS X's Finder has a function that works with the dedicated archiver (BOMArchiveHelper.app), and when you execute the "Compress" menu from the context menu, the file selected at that time is compressed "Archive.zip". Is generated. Extracting (decompressing) is even easier, just double-click.
It's a feature that's taken for granted now, but it didn't happen before OS X 10.3 (Panther). There was no way to handle the unique information that came with the file, which has been used since the old Mac OS.
In Mac OS, in addition to the file itself (data fork), there is a part called "resource fork" that can store various data. In addition, there is "metadata" that summarizes data such as the date and time when the file was created / modified / accessed, comments, and Finder information, and the "file" on the Finder can be reproduced only when these are collected.
However, resource forks and metadata are OS X / Finder-specific resources and are not needed by other operating systems. Apple has prepared a data format "AppleDouble" that divides the file into two parts, a data fork and other, so that you can see the difference between both when using it on OS X and the data fork when using it in other environments, Finder And the archiver was set up.
When you unzip a ZIP file created on OS X on Windows, a folder called "__MACOSX" is created in addition to the file. The contents of this folder are the parts other than the AppleDouble data fork (resource fork + metadata).
That is, the "__MACOSX" folder is irrelevant to anyone other than OS X users. Similarly, files (AppleDouble Header) that start with "._", which stores parts other than the data fork, are not referenced in other OSs. If you get a question from a Windows user, what's this? It doesn't matter to you, so delete it and answer clearly.
The current Finder has a function that allows you to easily create a ZIP archive, but ... |
When I open a ZIP archive created with Finder (BOMArchiveHelper) on another OS, it almost certainly contains the "__MACOSX" folder. |
To avoid including extra "__MACOSX"
However, the above is for the convenience of OS X users. Some people will ask you what this is (there are also around me) every time, and others will ask you not to add extra things! Certainly, it is good manners to give only what the other person needs.
A quick way to create a ZIP archive without resource forks or metadata is to use the "zip" command from Terminal. The usage is simple, just list the archive name (* .zip) to be generated in the first argument and the file / folder name to be compressed in the subsequent arguments. The ZIP archive created in this way should not show the "__MACOSX" folder even if it is expanded on Windows.
By the way, be careful when creating an archive (* .tar.gz / *. Tgz) with the tar command. For files with resource forks / metadata, the "__MACOSX" folder isn't created, but the AppleDouble Header is. If you're curious, choose ZIP Archive.
$ zip sample.zip file1.png file2.png
As you can see, the archive created by the zip command does not include the "__MACOSX" folder. |
This solves the "__MACOSX problem", but don't forget the ".DS_Store problem". This file, which records the position of the icon on the folder, is also irrelevant to users of other OSs, and it makes me worry that there is something wrong with not being able to open it.
As mentioned above, there is no problem if the compression target is only files, but if you target folders, ".DS_Store" will almost always be mixed in the archive. Therefore, before executing the zip command, execute the following command and delete all ".DS_Store" under the current directory. The details of the find and xargs commands are introduced in Part 28 of this series, so please refer to that as well.
$ find . -name '.DS_Store' -print0 | xargs -0 rm$ zip -r sample.zip file1.png file2.png picfolder
Related article |
[Column] New OS X hacking! (28) Year-end special project: Cleaning up home folders (December 26, 2011) |
[Review] "Paragon NTFS for Mac OS X 9" that can read and write NTFS at high speed (September 23, 2011) |
[Column] New OS X hacking! Just before Lion, smart HDD health diagnosis (June 24, 2011) |
[Column] OS X Hacking! Countdown to the 333rd Snow Leopard, and that's why it's backed up with "Time Machine" (August 24, 2009) |
[Column] OS X Hacking! Monitor HDD Lifespan in the 229th SMART (June 8, 2007) |