7-Zip, Software

Usable 7-Zip Commands

usable-7-zip-commands

7-Zip is a cross-platform, open source, free, powerful archive tools.

However, 7-Zip provides Windows GUI only, the other OS such as Linux and Macintosh do not have GUI.
You still can use another GUI archive management tools also can perform a 7-Zip format archive,
but if you do not have GUI, how could you archive data with 7-Zip ?

Visit http://www.7-zip.org/download.html and select the version you would like to install
If you are using Ubuntu you just type

sudo apt-get install p7zip p7zip-full p7zip-rar

If you are using Mac OS, visit http://7zx.en.softonic.com/mac to download 7zX

7-Zip uses 7z or 7za or 7zr or p7zip as its command header
Basically, 7z and 7za is the same command.
7z is the execute file installed in Windows OSs named 7z.exe in 7-Zip directory
7z and 7za and 7zr and p7zip
7z and 7za normally are the same, different of them is 7za is a stand-alone executable
so its filesize is more than 7z, and 7za contains less archive format than 7z
7zr is the same as 7za unless one operation – 7zr does not provide password settings.
p7zip is a lightweight 7-Zip command provides decompression operation only (and the help menu display operation)

Standard commands: 7z <command>

Archive a file:

7z a output input

a is the Archive command
output is the name of output file
If you don’t indicate the file extension, 7-Zip will add .7z for the output file by default
If the output exist, you will add the input into the exist archive
However, if the archive contains the same name of file, it will be overwritten
input is the name of input file
input can be a chain of files and directories, like
If you don’t indicate input, you will archive all the files and directories in current directory

7z a output file1 file2 directory1 directory2 data*

List inner files and directory in an archived file:
Sometimes you should observe the archive before you extract an archive

7z l input

l is the List command
input is the name of archive file

Delete specific files and directory in an archived file:
Sometimes you archive a list of files and directories but some of them are unnecessary
Delete the archive file and re-archive the list of files and directory is one of solutions
However, if your archive contains many files and directory, or the files are large size
You will spend a lot of time to re-archive them
So delete them one by one

7z d input inner

d is the Delete command
input is the name of archive file
inner is the name file or directory inside the archive
inner can be a chain of files and directories, like

7z e input inner1 inner2 innerdir1 innerdir2 data*

It will delete all files and directory in the archive, if you forget specify the inner files or directory

Extract specific files and directory in an archive file:
After you observe the archive, you know which file you should extract to
Sometimes the archive contains so many files but a few files you need to extract only,
whether you should not waste your time your extract non-used files

7z e input inner

e is the Extract command
input is the name of archive file
inner is the name file or directory inside the archive
inner can be a chain of files and directories, like

7z e input inner1 inner2 innerdir1 innerdir2 data*

It will prompt to confirm if the directory contains the same name of file
If you don’t specify a inner file or directory, it will extract all data in archive
but deploy all files and directories in current directory
If the archive contains many files and directories, make sure your command specify the inner file or directories
otherwise, the current directory will expands a lot of files and directories

Extract an archive file with full paths

7z x input

x is the eXtract command
input is the name of archive file
You can use this command to extract the archive file with full paths (structural directory) and
create a directory with same name of the archive file automatically
If there are a list of separated parts of files,
Move them into a same directory and extract the first part of archive file

Options: 7z <command> <options>

Compress ratio: -mx?

7z a -mx5 output input

-mx is the compress ratio option
There are 6 levels for compression
-mx0 absolutely speedy, but don’t have any compression, just like a copy but increase about 100KB
-mx1 fastest, lowest compress ratio
-mx3 fast, low compress ratio
-mx5 normal speed, normal compress ratio, which is the default compress ratio
-mx7 slow, high compress ratio
-mx9 slowest, highest compress ratio, the maximum up to 1:7000

Archive Type: -t?
There are 7 archive types
-t7z archive as 7-Zip format, which is the default archive type
-tgzip archive as GZip format
-tzip archive as Zip format, which is a compatible archive format
-tbzip2 archive as BZip2 format
-ttar archive as Tar format, popular in Linux and Unix Operating Systems
-tiso archive as ISO format
-tudf archive as UDF format
For example:

7z a -ttar output input

In this case, if you add an file extension when archive some input data, for example

7z a output.tar input

7-Zip will use the specific archive type, otherwise, all unknown archive type will represent 7-Zip
The Priority of -t? is higher than .ext

7z a -t7z output.tar input

This command will perform an archive with 7-Zip format, .tar will be ignored

Extract position: -o?
Set output destination when using extract operation, for example

7z x -o/tmp input

Archive with password: -p
Create an archive file with password

7z a -p output input

After execute this command, 7-Zip will ask you to enter a password,
So you don’t need to enter password after -p

Create a list of separated the files: -v?

7z a -v100K output input

K means Kilobytes
M means Megabytes
G means Gigabytes
100K means 100 Kilobytes
You can specific a number and unit that you would like to use, if you no specific the unit, it represents Bytes

Create a Self-Extracting Archive file: -sfx

7z a -sfx output input

If you are using Windows the output file will add .exe file extension
In Linux / Unix Operation System we suggest to add .bin file extension
You cannot extract the Self-Extracting Archive in Windows if the Archive create in Linux / Unix
You cannot extract the Self-Extracting Archive in Linux / Unix if the Archive create in Windows

7-Zip has more commands and options but we just introduce some always use commands and options
If you would to study whole information of 7-Zip, type

7z --help

or

man 7z

to learn about 7-Zip