Osx Command Line Zip
This article will help you understand how you can handle the common file formats TAR, GZIP, BZIP and ZIP on Linux operating systems (including CentOS, Ubuntu) and even some Unix-based OSes like MacOS (OS X) via the command line either via SSH or a local terminal session.
How to Install the Needed Tools
MacOS – How to install 7zip so I can run it from Terminal on OS X. 7-zip macos terminal.app. I would like to be able to run 7zip from the command line on Mac. Does anyone have instructions on how to set this up? Zip archives can also be created from the command line by using the terminal command ‘zip’ with the following syntax: zip archive.zip file.txt Another simple way to create an archive from the command line is to use the Terminal’s drag & drop support, type out ‘zip’ as usual but then drop in the file(s) to compress into the Terminal. However, I am unable to find the wget command on OS X. How do download files from the web via the Mac OS X bash command line option? You need to use a tool (command) called curl. It is a tool to transfer data from or to a server, using one of the following supported protocols. RAR 5.0 archive format. RAR 5.0 archive format description. UnRAR for Windows. Command line freeware Windows UnRAR. WinRAR for Linux. WinRAR WINE wrapper allowing to run WinRAR in Linux. Follow instructions in ReadMe.txt file. This package is prepared by Karsten Pedersen. UnRAR for Windows CE phones. The corresponding gunzip and bunzip2 commands can be used to uncompress said archive, or you can just use flags on the tar command to perform the uncompression. If you are referring specifically to the Zip file format, you can simply use the zip and unzip commands. To compress: zip squash.zip file1 file2 file3 or to zip a directory.
On many Linux-like operating systems the command line tools for working with TAR, GZIP, BZIP and ZIP files are already installed, so you almost certainly don't need to install anything, but if you are running a minimal installation of your OS or if you've removed the tools in the past, follow the directions below to install what you need. Select the tab for the OS you are running:
The directions below assume you are running as the root user. If you are running as an another user, you may need to prepend the commands with sudo.
Example: sudo yum install ...
- Pull up a terminal session or log into your server/computer via SSH.
The base repositories for these OSes have the packages we need. Execute the following command:
- If any of those are already installed, you will be informed. If any are missing, you will be asked if you want to install them. Answer y if everything looks ok.
- The system will download the needed packages and install them.
Now you should be able to follow the rest of the directions in this article.
The directions below assume you are running as the root user. If you are running as an another user, you may need to prepend the commands with sudo.
Example: sudo apt-get install ...
- Pull up a terminal session or log into your server/computer via SSH.
The base repositories for these operating systems have the packages we need. Execute the following command:
- If any of those are already installed, you will be informed. If any are missing, you will be asked if you want to install them. Answer y if everything looks ok.
- The system will download the needed packages and install them.
Now you should be able to follow the rest of the directions in this article.
The needed command line tools ship with every version of MacOS/OS X since at least 10.6 Snow Leopard (and may also be installed in earlier versions we were unable to test).
To work with files via the command line, open the Terminal application located in /Applications/Utilities/Terminal(.app).
Once the terminal is open, you will be able to follow the rest of the directions in this article.
Remember, you can drag and drop files or folders into the terminal application and the full path to those items will be pasted automatically into the command line.
Working with TAR Files
The TAR file format is a very early archiving format that doesn't include any active compression by default. Often on Linux, items are tarred and then gzipped to compress them. TAR files typically end in .tar.
Mac Command Line Zip With Password
Put a Directory into a TAR File
Execute the following to create a single .tar file containing all of the contents of the specified directory:
Replace FILENAME with whatever filename you want and DIRECTORY with the path to the directory you want to make into a tarball.
Command Flags Explanation
c: Create a TAR file.
v: Output verbosely (you'll be told exactly what is happening in detail).
f: Specify a filename for the resulting TAR file.
Put a Directory into a TAR file and Compress it with GZIP
Execute the following to create a single .tar.gz file containing all of the contents of the specified directory:
Replace FILENAME with whatever filename you want and DIRECTORY with the path to the directory you want to make into a compressed tarball.
Tarred files compressed with GZIP sometimes use the .tgz file extension.
Command Flags Explanation
c: Create a TAR file.
v: Output verbosely (you'll be told exactly what is happening in detail).
f: Specify a filename for the resulting TAR file.
z: Compress the TAR file with GZIP
Put a Directory into a TAR file and Compress it with BZIP2
Execute the following to create a single .tar.bz2 file containing all of the contents of the specified directory compressed with BZIP. (BZIP typically produces smaller files than GZIP, at the cost of more processing time.):
Replace FILENAME with whatever filename you want and DIRECTORY with the path to the directory you want to make into a compressed tarball.
Command Flags Explanation
c: Create a TAR file.
v: Output verbosely (you'll be told exactly what is happening in detail).
f: Specify a filename for the resulting TAR file.
j: Compress the TAR file with BZIP2
Extract Items from TAR Files
Execute the following command to extract files and directories from an uncompressed .tar file:
Replace FILE with the filename of the file you are trying to uncompress. The file will uncompress into the current directory.
Command Flags Explanation
x: Extract the contents from the file specified.
v: Output verbosely (you'll be told exactly what is happening in detail).
f: Specify a filename to uncompress.
Extract Items from GZIPPED Tarball File
Execute the following command to extract files and directories from a GZIP compressed TAR file:
Replace FILE with the filename of the file you are trying to uncompress. The file will uncompress into the current directory.
Command Flags Explanation
x: Extract the contents from the file specified.
v: Output verbosely (you'll be told exactly what is happening in detail).
f: Specify a filename to uncompress.
z: Uncompress the tarball via GZIP.
Extract Items from BZIPPED Tarball File
Execute the following command to extract files and directories from a BZIP compressed TAR file:
Replace FILE with the filename of the file you are trying to uncompress. The file will uncompress into the current directory.
Command Flags Explanation
x: Extract the contents from the file specified.
v: Output verbosely (you'll be told exactly what is happening in detail).
f: Specify a filename to uncompress.
j: Uncompress the tarball via BZIP2.
If you'd rather specify a different directory to extract files to rather than just dumping everything in the current directory add -C /PATH/TO/DIRECTORY/ to the commands above. Replace /PATH/TO/DIRECTORY/ with the actual path to the directory where you want the files to be placed.
Working with Zip Files
Zip is probably the most common compressed archiving format in the world. Zip files usually end in .zip.
Compress a Directory Full of Files into a ZIP File
Execute the following command to place everything inside a specified directory into a compressed ZIP file.
Command Flags Explanation
-r: Recursively compress all files and directories contained within DIRECTORY/ in the zip file (otherwise you only get the top level files).
Uncompress a ZIP file Into the Current Directory
Execute the following command to uncompress the items in the ZIP file into the current directory.
TheDeveloperBlog.com
Home Contact Us
CSharp Java Python Swift GO WPF Ruby Scala F# JavaScript
<< Back to C-SHARPTip: For convenience and so you don't need to change environment paths, put the 7za.exe file in your user directory.
Next: Open the Windows console and test the 7za.exe program out with a few commands. Type in the exe name 7za and this will display.
Grammar: We see the grammar we need to use with 7za.exe. The 'command' is the main verb.
Switches: Then you specify optional switches, the archive name (source or destination) and files. My user directory is 'C:UsersSam'.
Arguments: You have to specify the destination archive, and the source files (in that order).
Note: On the test system, 'C:UsersSam' contains two files (file1.txt and file2.txt). The command puts those two files in an archive.
Tip: To open your archive, right click on it and select 7-Zip -> Open archive. The screenshot shows the files compressed in files.7z.
Note: You will need this if you use huge archives and need to save time. This is from the manual.
Tip: You can also remove a single file from an archive with 'd'. This is more useful when you do not have a solid archive.
Info: The 'e' command extracts everything to a specified directory. Another command 'x' can preserve directory structures in archives.
Overwrite prompts: 7-Zip will always prompt you if there is a file it needs to overwrite to extract the new file.
However: This can be problematic if you are scripting or embedding 7za.exe. In that case, see the -y switch.
Next: This shows the listing of a solid archive. The originals are 27216 bytes and 3888 bytes. They compress down to 1030 bytes.
Warning: Don't confuse the two. This one is used for diagnostics. We usually want the hyphen '-t.'
Warning: The 'u' command doesn't work with solid archives. A solid archive is one where all the files are compressed together.
So: You cannot update specific files in solid archives with the 'u' command. Solid archives are limited.
Tip: It specifies the method of compression. Here I will show a bunch of options, and also some examples.
Switch -mfb: Specifies number of fast bytes. Sometimes helps with 'sparse' files. Don't bother.
Switch -mpass: Number of passes for deflate compression. Don't bother with this. Automatically set with levels.
Switch -md: This specifies dictionary size. It is automatically set, so don't bother.
Switch -mmt: Enable multithreading. Use if you have quad-core and a huge archive. Specify 'on' or 'off'.
Switch -ms=on: Enable solid mode. This is the default so you won't often need to specify it.
Switch -ms=off: Disable solid mode. Useful when you need to update individual files. Will reduce compression ratios normally.
PPMd switch -mmem=24b, -mmem=24k, -mmem=24m: These control the amount of memory you use. They are useful and higher is normally better.
PPMd switch -mo=2, -mo=32: These specify the model order in PPMd. They are not normally useful.
Tip: You should use PPMd when you have a large corpus (body) of text. This could include HTML. It can improve ratios by around 30%.
Tip: The command is useful because you will normally want to compress only text files with PPMd.
Header encryption: Add -mhe to encrypt headers. The password command will automatically deal with encrypted headers.
Tip: Remember, encrypted headers will hide the names of the files in your archive.
Switch -ssc: Specify case-sensitive mode. The default is -ssc- on Windows (insensitive). The default is -scc on Linux (sensitive).
Switch -ssw: Compress locked files. You can try this if you have problems opening files.
Switch -w: Set working directory. You can use this when you want to specify temp folders.

Also: You can specify sequential volumes with the 'v' switch on the 7za.exe command line.
Switch ao. The 'ao' switch allows you to specify whether you want to overwrite old files. Be careful—you cannot restore an overwritten file normally. This switch takes another argument.Switch -aoa: This switch overwrites all destination files. Use it when the new versions are preferred.
Switch -aos: Skip over existing files without overwriting. Use this for files where the earliest version is most important.
Switch -aou: Avoid name collisions. New files extracted will have a number appending to their names. You will have to deal with them later.
Switch -aot: Rename existing files. This will not rename the new files, just the old ones already there.
Mac Command Line Zip Multiple Files
How do I add many files with a specific extension? Use the 'a' command and the wildcard * symbol, but specify the extension after the wildcard.Example: For example, *.txt means all text files. You can use the wildcard anywhere.
Tip: Change the archive not to be solid if you want to update it. Search this page for 'solid'.
So: If you want to exclude 'file1.txt', use the switch '-x!file1.txt'. Please include the hyphen and exclamation.
Note: Use -aos if your files don't change over time and overwriting would just be a waste.
Filters: You can change compression filters, which change behaviors on executable files such as *.exe and *.dll.

And: You can enable header compression and encryption (-mhc=on and -mhe=on). Header compression is by default enabled.