Osx Zip Command Line



To zip a single file within a new compressed archive titled Photo.zip, such as the Product Shot.jpeg within the Marketing directory, enter the following command: zip Photo.zip 'Product Shot.jpeg'. For example: zip -f foo This command should be run from the same directory from which the original zip command was run, since paths stored in zip ar- chives are always relative. Note that the timezone environment variable TZ should be set according to the local timezone in order for the -f, -u and -o options to work correctly. The command zip -qdgds 10m will turn off most output except dots every 10 MB.ds size -dot-size size Set amount of input file processed for each dot displayed. See -dd to enable displaying dots. Setting this option implies -dd. Size is in the format nm where n is a number and m is a multi- plier.

Package and compress (archive) files.

will remove the entry foo/tom/junk, all of the files that start with foo/harry/, and all of the files that end with .o (in any
path). Note that shell pathname expansion has been inhibited with backslashes, so that zip can see the asterisks, enabling
zip to match on the contents of the zip archive instead of the contents of the current directory. (The backslashes are not
used on MSDOS-based platforms.) Can also use quotes to escape the asterisks as in

Not escaping the asterisks on a system where the shell expands wildcards could result in the asterisks being converted to a
list of files in the current directory and that list used to delete entries from the archive.
Under MSDOS, -d is case sensitive when it matches names in the zip archive. This requires that file names be entered in upper case if they were zipped by PKZIP on an MSDOS system. (We considered making this case insensitive on systems where paths were case insensitive, but it is possible the archive came from a system where case does matter and the archive could include both Bar and bar as separate files in the archive.) But see the new option -ic to ignore case in the archive.

zip is a compression and file packaging utility for Unix, VMS, MSDOS, OS/2, Windows 9x/NT/XP, Minix, Atari, Macintosh, Amiga, and Acorn RISC OS. It is analogous to a combination of the Unix commands tar(1) and compress(1) and is compatible with PKZIP (Phil Katz's ZIP for MSDOS systems).
A companion program (unzip(1L)) unpacks zip archives. The zip and unzip(1L) programs can work with archives produced by PKZIP (supporting most PKZIP features up to PKZIP version 4.6), and PKZIP and PKUNZIP can work with archives produced by zip (with some exceptions, notably streamed archives, but recent changes in the zip file standard may facilitate better compatibility). zip version 3.0 is compatible with PKZIP 2.04 and also supports the Zip64 extensions of PKZIP 4.5 which allow archives as well as files to exceed the previous 2 GB limit (4 GB in some cases). zip also now supports bzip2 compression if the bzip2 library is included when zip is compiled. Note that PKUNZIP 1.10 cannot extract files produced by PKZIP 2.04 or zip 3.0. You must use PKUN-ZIP 2.04g or unzip 5.0p1 (or later versions) to extract them.
See the EXAMPLES section at the bottom of this page for examples of some typical uses of zip.
Large Archives and Zip64. zip automatically uses the Zip64 extensions when files larger than 4 GB are added to an archive, an archive containing Zip64 entries is updated (if the resulting archive still needs Zip64), the size of the archive will exceed 4 GB, or when the number of entries in the archive will exceed about 64K. Zip64 is also used for archives streamed from standard input as the size of such archives are not known in advance, but the option -fz- can be used to force zip to create PKZIP 2 compatible archives (as long as Zip64 extensions are not needed). You must use a PKZIP 4.5 compatible unzip, such as unzip 6.0 or later, to extract files using the Zip64 extensions.
In addition, streamed archives, entries encrypted with standard encryption, or split archives created with the pause option may not be compatible with PKZIP as data descriptors are used and PKZIP at the time of this writing does not support data descriptors (but recent changes in the PKWare published zip standard now include some support for the data descriptor format zip uses).
Mac OS X. Though previous Mac versions had their own zip port, zip supports macOS as part of the Unix port and most Unix features apply. References to 'macOS' below generally refer to macOS versions older than macOS. Support for some Mac OS features in the Unix macOS port, such as resource forks, is expected in the next zip release.
For a brief help on zip and unzip, run each without specifying any parameters on the command line.

The program is useful for packaging a set of files for distribution; for archiving files; and for saving disk space by temporarily compressing unused files or directories.
The zip program puts one or more compressed files into a single zip archive, along with information about the files (name, path, date, time of last modification, protection, and check information to verify file integrity). An entire directory structure can be packed into a zip archive with a single command. Compression ratios of 2:1 to 3:1 are common for text files. zip has one compression method (deflation) and can also store files without compression. (If bzip2 support is added, zip can also compress using bzip2 compression, but such entries require a reasonably modern unzip to decompress. When bzip2 compression is selected, it replaces deflation as the default method.) zip automatically chooses the better of the two (deflation or store or, if bzip2 is selected, bzip2 or store) for each file to be compressed.

EXAMPLES

PATTERN MATCHING

This section applies only to Unix. Watch this space for details on MSDOS and VMS operation. However, the special wildcard characters * and [] below apply to at least MSDOS also.
The Unix shells (sh, csh, bash, and others) normally do filename substitution (also called 'globbing') on command arguments. Generally the special characters are:

When these characters are encountered (without being escaped with a backslash or quotes), the shell will look for files relative to the current path that match the pattern, and replace the argument with a list of the names that matched.
The zip program can do the same matching on names that are in the zip archive being modified or, in the case of the -x (exclude) or -i (include) options, on the list of files to be operated on, by using backslashes or quotes to tell the shell not to do the name expansion. In general, when zip encounters a name in the list of files to do, it first looks for the name in the file system. If it finds it, it then adds it to the list of files to do. If it does not find it, it looks for the name in the zip archive being modified (if it exists), using the pattern matching characters described above, if present. For each match, it will add that name to the list of files to be processed, unless this name matches one given with the -x option, or does not match any name given with the -i option.
The pattern matching includes the path, and so patterns like *.o match names that end in '.o', no matter what the path prefix is. Note that the backslash must precede every special character (i.e. ?*[]), or the entire argument must be enclosed in double quotes (').
In general, use backslashes or double quotes for paths that have wildcards to make zip do the pattern matching for file paths, and always for paths and strings that have spaces or wildcards for -i, -x, -R, -d, and -U and anywhere zip needs to process the wildcards.

ENVIRONMENT

Exit codes:

zip 3.0 is not compatible with PKUNZIP 1.10. Use zip 1.1 to produce zip files which can be extracted by PKUNZIP 1.10.

“He can compress the most words into the smallest ideas of any man I ever met” ~ Abraham Lincoln

Related macOS commands:

Osx Zip Command Line

cpio - Copy files to and from archives.
zipcloak (see man page)
zipnote (see man page)
zipsplit (see man page)
tar - Store, list or extract files in an archive.
compress(1), shar(1L), unzip(1L), gzip(1L)

Copyright © 1999-2021 SS64.com
Some rights reserved
By Xah Lee. Date: . Last updated: .

This page is tips about Mac OS X's command line tools about Mac's resource fork.

The info on this page is tested on Mac OS X 10.4.x and OS X 10.6.x.

Note: since Mac OS X 10.7 (released in 2011), the old syntax for accessing resource fork no longer works. The new syntax is

ls -l filename/..namedfork/rsrc

Resource Fork

What is a resource fork?

Resource fork is a feature of the Mac's file system HFS Plus, and older file systems used by Mac such as HFS and “Macintosh file system”.

Mac Zip Command Line Options

A file has 2 parts: ① data fork, ② resource fork. The data fork is the file's main content, the resource fork stores some extra data such as icon, version number, embedded images, image thumbnail, and much more.

Some app store main data in resource fork. For example, Quick Time movie files used to store main movie data in the resource fork. This means, you should not simply remove resource fork data.

Is resource fork still used?

Yes. The use of resource fork is discouraged for normal files. However, program executable files such as those “.app” may still need the resource fork intact to work, and many programs, including Apple's software, still create resource fork as of .

for example, see: Safari “.webloc” File.

How to use the command line to find out if a file has resource fork?

Use the ls -l command with /rsrc suffixed to the file name.

Note: since Mac OS X 10.7 (released in 2011), you have to use /..namedfork/rsrc.

Mac 7 Zip Command Line

For example, ls -l file.png/rsrc. If the reported file size is 0, then it has no resource fork. Here's a command line log as a example:

The file size reported by the unix command “ls”, does it count resource fork?

No. (but if you append your file name with “/rsrc”, then “ls” will report the resource fork's file size.)

How to delete a file's resource fork using command line?

You can overwrite it with a empty file. Suppose you want to delete resource fork in “file.png”.Do like this:

See also: Perl Script for Removing Mac Resource Fork.

How to delete a file properly (including resource fork) using the command line?

Using /bin/rm is probably doing the right thing. To be safe, one can delete the resource fork first. Example:

When using “get info” in Finder, it reports file size by two numbers, for example, “592KB on disk (601,189 bytes)”. What's these two figures exactly? and does KB mean 1024 bytes or 1000 bytes? Does either count the resource fork?

The one in parenthesis is the actual file size (counting the resource fork). The one not in paren is the disk space it occupies, and the M and K abbreviations are multiples of 1024.

FileFinderls
alice.jpg (has resource fork)584 KB on disk, (595,041 bytes)484995
alice2.jpg (no resource fork)476 KB on disk, (484,995 bytes)484995

Note: starting with OS X 10.6, k may mean 1000, not 1024. See: Computing: mega vs mibi, kilo vs kibi.

Does “cp” command copy resource fork?

Yes, as of Mac OS X 10.4

How to view resource?

Look at /usr/bin/DeRez. Type “man DeRez” to read how to use it.

In 10.4, resource fork related tools are available on the Developers tools CD that came with Mac OS X at least 10.1 up to 10.4. When installed, it's at /Developer/Tools/.

File Type/Creator

File Type and Creator

What is a File Type/Creator code?

In Windows, file names has a suffix, for example, {.txt, .jpg, .bat, .dll}. This suffix indicates the file's type, and what application is used when user tries to open them. (See: filename extension)

In Mac Classic, the file type and the application associated with the file is stored with the file in the file system. This is the file type and creator code.(See: Type code andCreator code.)

In Mac OS X, the use of file type and creator code is discouraged and is no longer supported starting with Mac OS X 10.6 “Snow Leopard” (2009).

Is file type and creator stored in resource fork?

Osx Zip With Password Command Line

No.File {type, creator} info is stored in the metadata that {HFS, HFS+} file systems support,along with lock/unlock status, the flag that says whether there's acustom icon, date/time created/modified, etc.

The file type/creator info, and any resource fork, are both lost when transferring the file to other OS without care. When using unix command line utils (cp, tar, gz, etc), whether these data are kept depends on which command you are using. Also, each version of OS X, Apple updates some command line tools so that they preserve these data.

How to find out a file's type and creator code using the command line?

Use “GetFileInfo”. Example:

The “-c” is for creator code, the “-t” is for file type code.

In 10.6, the command “GetFileInfo” is at /usr/bin/.

Command

How to change a file's type and creator code using the command line?

Use the command “SetFile”. Like this:

If you want to set it to a bunch of files in dir, you can do it like this:

In the above example, all file in the current dir and all sub dir, whose name ends in “.gsp”, will now have a creator code of “GSP+” and file type code of “GSPb”.

File Compression with Meta data

How to create a zip file that preserves Mac meta data?

For 10.6.x, in Finder, right click on a file and pull the menu “Compress ‹name›”. This will create a zip file with all meta data preserved.

In 10.4.x, the menu is “Create Archive of ‹folder name›”.The command line equivalent is:ditto -ck --sequesterRsrc --keepParent myFolder myFolder.zip.

The above method puts the resource forks and HFS meta-data into a subdirectory “__MACOSX__”. You may just want to use this instead:ditto -ck --rsrc --keepParent myFolder myFolder.zip.

Note: Mac OS X 10.5 changed the tool it uses for dealing with zip files.Its new compression tool is The Unarchiver.For detail, see Archive Utility (aka BOMArchiveHelper).

How to unpack a zip file that has Mac meta data?

In Finder, double click on a file. The command line equivalent isditto -xk myFolder.zip myFolder.

Does the command line program “zip” and “unzip” understand metadata?

No, as of Mac OS X 10.6.2. The command line tools at /usr/bin/zip and /usr/bin/unzip do not understand Mac meta data.

Zip

Using command line zip will simply create a archive without Mac metadata. Using unzip to unzip a zipped folder that has Mac metadata, will create a extraneous directory “__MACOSX__” and or extraneous files with names prefixed by “.”.

Does tar, gzip, gunzip understand Mac metadata?

On OS X 10.6.3, tar, gzip, gunzip, will preserve resource fork. On OS X 10.4, no. I haven't tested whether 10.6 preserves file creator and type code.

Note that if you want to preserve resource fork, you must use the version supplied with the Mac 10.6.x, at /usr/bin. This means if you have installed GNU's version (from Fink or MacPorts), remember to start you command with full path 〔/usr/bin/…〕 if you still want resource fork.

Also, if you unzip and untar using a version that does not understand resources, your resources will be lost.

For example, you can do tar cvf myfolder.tar myfolder. This will result a new file named tar cvf myfolder.tar. This file itself will have no resource fork. All the resources are embedded in the file. Now, move the tar file to a new dir, untar it by tar xvf myfolder.tar. The result dir's files will still have resource fork.

Also, it appears that, whether tar, gzip, gzip understand resource fork depends on a undocumented environment variable. For OS X 10.4, this variable is COPY_EXTENDED_ATTRIBUTES_DISABLE. It can be set to “true” or “false”, but in OS X 10.5, this variable changed name to COPYFILE_DISABLE.This info is from:[Resource forks and tar By Norman Walsh. At http://norman.walsh.name/2008/02/22/tar , accessed on 2014-01-18 ]I have not verified it.

Line

Do you have a folder with Mac metadata i can download and test?

Yes. download this file:macosx_metadata_test.zip.After download, do not use /usr/bin/unzip to decompress it, because that would lose the meta data. Use this instead:

Thanks to Mark Reed, Kris Gybels, for corrections on the zip utility.

If you have a question, put $5 at patreon and message me.