2018-11-13 08:54:50 +00:00
|
|
|
---
|
|
|
|
layout: page
|
|
|
|
category-page: intermediate
|
2018-11-16 12:47:48 +00:00
|
|
|
category-title: Intermediate commands
|
|
|
|
tags: compress archive extract
|
2018-11-13 08:54:50 +00:00
|
|
|
author: Andrea Brites Marto
|
|
|
|
title: 7z
|
|
|
|
---
|
2018-11-16 09:57:05 +00:00
|
|
|
<p>
|
2018-11-15 20:09:21 +00:00
|
|
|
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.<br>
|
2018-11-15 08:05:41 +00:00
|
|
|
|
2018-11-15 20:09:21 +00:00
|
|
|
So, first of all, you need to download Unarchiver in order to use this command.<br>
|
2018-11-15 08:05:41 +00:00
|
|
|
|
2018-11-15 20:09:21 +00:00
|
|
|
The basic syntax is:
|
2018-11-16 09:57:05 +00:00
|
|
|
</p>
|
2018-11-15 16:19:19 +00:00
|
|
|
<pre>
|
2018-11-15 20:09:21 +00:00
|
|
|
7z [adeltux] [-] [SWITCH] <code><ARCHIVE_NAME> <ARGUMENTS></code>
|
2018-11-15 16:19:19 +00:00
|
|
|
</pre>
|
|
|
|
|
|
|
|
Here some useful options that we will use to explain some examples:
|
|
|
|
|
|
|
|
<ul>
|
2018-11-15 20:09:21 +00:00
|
|
|
<li><i>a</i> Add</li>
|
|
|
|
<li><i>d</i> Delete</li>
|
|
|
|
<li><i>e</i> Extract</li>
|
|
|
|
<li><i>l</i> List</li>
|
|
|
|
<li><i>t</i> Test</li>
|
|
|
|
<li><i>u</i> Update</li>
|
|
|
|
<li><i>x</i> Extract with full paths</li>
|
2018-11-15 16:19:19 +00:00
|
|
|
</ul>
|
|
|
|
|
2018-11-15 20:09:21 +00:00
|
|
|
The simplest way to use <code>7z</code> if we want to extracts all files
|
|
|
|
from archive archive.zip to the current directory.
|
2018-11-15 16:19:19 +00:00
|
|
|
|
|
|
|
<pre>
|
2018-11-15 20:09:21 +00:00
|
|
|
7z e archive.zip
|
2018-11-15 16:19:19 +00:00
|
|
|
</pre>
|
|
|
|
|
2018-11-16 09:57:05 +00:00
|
|
|
<p>Well, now we talk about the switches.
|
|
|
|
There are many type of switches, we will see the most common ones.</p>
|
2018-11-15 16:19:19 +00:00
|
|
|
|
2018-11-16 09:57:05 +00:00
|
|
|
<h3>-m (Set compression Method)</h3>
|
2018-11-15 16:19:19 +00:00
|
|
|
|
|
|
|
<p>Specifies the compression method</p>
|
2018-11-15 20:09:21 +00:00
|
|
|
|
2018-11-15 16:19:19 +00:00
|
|
|
<pre>
|
2018-11-15 20:09:21 +00:00
|
|
|
-m<method_parameters>
|
2018-11-15 16:19:19 +00:00
|
|
|
</pre>
|
|
|
|
|
|
|
|
The format for this switch depends on the archive type which are:
|
|
|
|
<ul>
|
2018-11-15 20:09:21 +00:00
|
|
|
<li>Zip</li>
|
|
|
|
<li>GZip</li>
|
|
|
|
<li>BZip2</li>
|
|
|
|
<li>7z</li>
|
|
|
|
<li>XZ</li>
|
|
|
|
<li>WIM</li>
|
2018-11-15 16:19:19 +00:00
|
|
|
</ul>
|
|
|
|
|
2018-11-15 20:09:21 +00:00
|
|
|
<h3>-r (Recurse subdirectories) switch</h3>
|
2018-11-15 16:19:19 +00:00
|
|
|
|
|
|
|
<p>Specifies the method of treating filenames or wildcards on the command line.</p>
|
|
|
|
The syntax:
|
|
|
|
|
|
|
|
<pre>
|
2018-11-15 20:09:21 +00:00
|
|
|
-r[- | 0]
|
2018-11-15 16:19:19 +00:00
|
|
|
</pre>
|
|
|
|
|
|
|
|
<table>
|
2018-11-15 20:09:21 +00:00
|
|
|
<tr>
|
|
|
|
<td>Switch</td>
|
|
|
|
<td>Description</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>-r</td>
|
|
|
|
<td>Enable recurse subdirectories</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>-r-</td>
|
|
|
|
<td>Disable recurse subdirectories. This is the default option.</td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>-r0</td>
|
|
|
|
<td> Enable recurse subdirectories only for wildcard names </td>
|
|
|
|
</tr>
|
2018-11-15 16:19:19 +00:00
|
|
|
</table>
|
|
|
|
|
|
|
|
<p>
|
2018-11-15 20:09:21 +00:00
|
|
|
If we want to list all *.doc files that belong to the archived root directory in
|
|
|
|
the <i>archive.zip</i> archive, we can do as follows:
|
2018-11-15 16:19:19 +00:00
|
|
|
</p>
|
|
|
|
|
|
|
|
<pre>
|
2018-11-15 20:09:21 +00:00
|
|
|
7z l archive.zip *.doc -r-
|
2018-11-15 16:19:19 +00:00
|
|
|
</pre>
|
2018-11-15 08:05:41 +00:00
|
|
|
|
2018-11-15 20:09:21 +00:00
|
|
|
<h3>-p (Set password) switch</h3>
|
2018-11-15 08:05:41 +00:00
|
|
|
|
2018-11-15 16:19:19 +00:00
|
|
|
<p>Specifies a password</p>
|
|
|
|
Here the syntax is very simple:
|
2018-11-15 08:05:41 +00:00
|
|
|
|
2018-11-15 16:19:19 +00:00
|
|
|
<pre>
|
2018-11-15 20:09:21 +00:00
|
|
|
-p{password}
|
2018-11-15 16:19:19 +00:00
|
|
|
</pre>
|
2018-11-15 08:05:41 +00:00
|
|
|
|
2018-11-15 20:09:21 +00:00
|
|
|
If we want to protect some files we can compress for example all *.txt files
|
|
|
|
to archive.7z using a password as "cimbale".
|
2018-11-15 08:05:41 +00:00
|
|
|
|
2018-11-15 16:19:19 +00:00
|
|
|
<pre>
|
2018-11-15 20:09:21 +00:00
|
|
|
7z a archive.7z -p cimbale
|
2018-11-15 16:19:19 +00:00
|
|
|
</pre>
|
2018-11-15 08:05:41 +00:00
|
|
|
|
2018-11-15 16:19:19 +00:00
|
|
|
Then if we want to extracts all files from archive.7z we need the password "cimbale".
|
2018-11-15 08:05:41 +00:00
|
|
|
|
2018-11-15 16:19:19 +00:00
|
|
|
<pre>
|
2018-11-15 20:09:21 +00:00
|
|
|
7z x archive.7z -p cimbale
|
2018-11-15 16:19:19 +00:00
|
|
|
</pre>
|
|
|
|
|
2018-11-15 20:09:21 +00:00
|
|
|
<h3>-x (Exclude filenames) switch </h3>
|
2018-11-15 16:19:19 +00:00
|
|
|
|
|
|
|
<p>
|
2018-11-15 20:09:21 +00:00
|
|
|
Specifes which filenames or wildcards must be excluded from the operation.
|
2018-11-15 16:19:19 +00:00
|
|
|
</p>
|
2018-11-15 20:09:21 +00:00
|
|
|
|
2018-11-15 16:19:19 +00:00
|
|
|
Syntax:
|
2018-11-15 08:05:41 +00:00
|
|
|
|
2018-11-15 16:19:19 +00:00
|
|
|
<pre>
|
2018-11-15 20:09:21 +00:00
|
|
|
-x[<recurse_type>]<file_ref>
|
2018-11-15 16:19:19 +00:00
|
|
|
</pre>
|
2018-11-15 08:05:41 +00:00
|
|
|
|
2018-11-15 16:19:19 +00:00
|
|
|
Sometimes we need to add files into an archive.7z, except one, this can be done as fllows:
|
2018-11-15 08:05:41 +00:00
|
|
|
|
2018-11-15 16:19:19 +00:00
|
|
|
<pre>
|
2018-11-15 20:09:21 +00:00
|
|
|
7z a -tzip archive.7z *.txt -x!temp.*
|
2018-11-15 16:19:19 +00:00
|
|
|
</pre>
|
2018-11-15 08:05:41 +00:00
|
|
|
|
2018-11-15 16:19:19 +00:00
|
|
|
<p>We described the most important swtiches and uses of this command, but there are more.</p>
|