--- layout: page category-title: Intermediate commands category-page: intermediate tags: author: Andrea Brites Marto title: 7z ---

A .7z. file is an archive format that stands for 7-zip. By default, Mac OS X does not know how to handle these files, but that is not a big deal because you can download for free in App Store. The program supports 7z, ZIP, CAB, ARJ, BZIP2, TAR, CPIO, RPM and DEB.
So, first of all, you need to download Unarchiver in order to use this command.
The basic syntax is:

7z [adeltux] [-] [SWITCH] <ARCHIVE_NAME> <ARGUMENTS>
Here some useful options that we will use to explain some examples: The simplest way to use 7z if we want to extracts all files from archive archive.zip to the current directory.
7z e archive.zip

Well, now we talk about the switches. There are many type of switches, we will see the most common ones.

-m (Set compression Method)

Specifies the compression method

-m<method_parameters>
The format for this switch depends on the archive type which are:

-r (Recurse subdirectories) switch

Specifies the method of treating filenames or wildcards on the command line.

The syntax:
-r[- | 0]
Switch Description
-r Enable recurse subdirectories
-r- Disable recurse subdirectories. This is the default option.
-r0 Enable recurse subdirectories only for wildcard names

If we want to list all *.doc files that belong to the archived root directory in the archive.zip archive, we can do as follows:

7z l archive.zip *.doc -r-

-p (Set password) switch

Specifies a password

Here the syntax is very simple:
-p{password}
If we want to protect some files we can compress for example all *.txt files to archive.7z using a password as "cimbale".
7z a archive.7z -p cimbale
Then if we want to extracts all files from archive.7z we need the password "cimbale".
7z x archive.7z -p cimbale

-x (Exclude filenames) switch

Specifes which filenames or wildcards must be excluded from the operation.

Syntax:
-x[<recurse_type>]<file_ref>
Sometimes we need to add files into an archive.7z, except one, this can be done as fllows:
7z a -tzip archive.7z *.txt -x!temp.*

We described the most important swtiches and uses of this command, but there are more.