Macos Zip Command Line

  

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.

Zip

If the two methods from above don’t work, a third option to unzip a CPGZ file on Mac OS X is to use the command line unzip tool. Generally, this is used to break archives out of the.zip to.

In shock I went back and checked my file on my mac and confirmed that I wasn't crazy and that it was still password protected there. (If this makes you nervous, perhaps you can check if google drive opens your mac-command-line-encrypted zip files too). I'm using mavericks OS X (v. 10.9.5) on my macbook air (fall 2012). This is the equivalent of the Command Prompt on Windows and allows Mac OS X users to perform a variety of commands. This is how you can create a.zip archive with nothing but the command line in Mac. First, you’ll need to open the Terminal. There are several ways to do this: Press the command (⌘) and Space keys at the same time. On your Mac, do any of the following: Compress a file or folder: Control-click it or tap it using two fingers, then choose Compress from the shortcut menu. If you compress a single item, the compressed file has the name of the original item with the.zip extension. If you compress multiple items at once, the compressed file is called Archive.zip.

How to Install the Needed Tools

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:

Line


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.

Os x zip command line

Example: sudo yum install ...

  1. Pull up a terminal session or log into your server/computer via SSH.
  2. The base repositories for these OSes have the packages we need. Execute the following command:

  3. 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.
  4. 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 ...

Mac os command line zip with password
  1. Pull up a terminal session or log into your server/computer via SSH.
  2. The base repositories for these operating systems have the packages we need. Execute the following command:

  3. 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.
  4. 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.

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.

Macos Zip Command Lines

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.

Macos zip command lines

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

Macos Zip Command Line Password

-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

Macos Unzip Zip File Command Line

Execute the following command to uncompress the items in the ZIP file into the current directory.