Linux compression decompression software 7zip (will not extract RAR to see) __linux

Source: Internet
Author: User
Tags compact extract rar file rar switches

Original: http://www.linuxdiyf.com/viewarticle.php?id=193969

Note: Just want to know how to extract the RAR format friends can jump directly to the back, but note to install the 7zip rar module another: Linux can also be installed Unrar to extract RAR files, here Conlio
Brief Introduction
7-zip is a cross-platform open source compression/decompression software, the official website is http://www.7-zip.org, support 7z, zip, GZIP, BZIP2, tar and other formats, and can extract RAR file (Note: Due to the protocol relationship, temporarily can not compress into the RAR format), In the function and compression rate can be comparable with WinRAR. Under the Linux can not extract RAR files of comrades have hope.

about the 7z format
Similar to the RAR format, the 7z format is a compression format that supports different compression rates. Its highest compression rate than the RAR format is also higher (that is, the size of the compressed file, smaller than the RAR format), of course, the higher the compression level, compression/decompression needs more time, The higher the memory consumed (or even the size of the memory that can be allocated to 7zip, pay special attention), the lowest compression level is 0, packaged for only.

installation
Debian/ubuntu can look for a new manager or software Center, search "7z", you can see the p7zip, such as the package, install it.need the support of RAR format users, also need to install 7zip rar module, you can use it after you've installed it.
The Apt-get install P7zip-full can be used under the command line (Ubuntu users can directly add Sudo,debian before the user may need to switch to root with su)
Fedora and Debian/ubuntu are similar, here Conlio.
openSUSE users please open the official soft station, address is http://software.opensuse.org, enter "7zip" in the Search box, and select your version, search, usually the first installation.
Other distributions can be found either from their source or from http://www.7-zip.org/download.html, http://sourceforge.net/projects/p7zip/files/p7zip/ To find the appropriate package or source code for installation.
Windows users please look for the download from the http://www.7-zip.org/download.html, the installation process is very simple, here Conlio.

How to use the 7-zip at the command line
Use Format
: 7z [Adeltux] [-] [SWITCH] ...
The first 7z is the name of the program, 7zip after loading will have 7z, 7za, 7ZR three programs, where 7z is fully functional (that is, enable all modules of the function), 7za is only the use of 7zip itself, do not enable other modules (this situation does not support the format of RAR), 7ZR is a compact version, only support 7z format.
The second parameter [Adeltux] is used to tell 7zip what function to perform:a used to create a compressed file or to add a file to a compressed filed used to delete files from a compressed fileE is for decompression, but does not create a directory structure; L is used to show what is contained in a compressed file; t is used to test whether the compressed file is valid; U is used to update the files in the compressed file;x for decompression and create the directory structure
[-] [Switch] is an option switch, some of the options will be described later, or you can use the command man 7z to view detailed instructions.
is the file name of the compressed file, followed by the file name of the input file (you can use wildcard characters, you can have multiple files).
the more commonly used option switches
-T: Specify a compressed format, such as-t7z
-M: Set the compression method, as detailed in [url=file:///usr/share/doc/p7zip-full/docs/manual/switches/method.htm]/usr/share/doc/p7zip-full/ Docs/manual/switches/method.htm[/url] (under Debian, if not open, please refer to your own man page)
-P: Set a password for the compressed file, either in the compression of the input command plus-p, and then enter the password in the execution, can also be directly-ppassword, such as-p123456
-mhe=on|off: For 7z format only, turn on or off encryption of file list, default to OFF
-si: Read data from standard input, often combined with pipe operations, for compressing/packaging files
-so: Write data to standard output, often combined with pipe operations to extract/release files
-V: For volume compression, for example, the maximum output of each file is 1MB, then use-v1m
-O: Store the extracted files in the specified directory, if you want to specify the uncompressed file output to directory A, then use-oa
-L: Store the corresponding File/directory for the symbolic link and replace it with this link (note that no recursive links are available in the compressed file)
about command return values
7-zip also has its own return value after exiting,to view the return value, execute the echo $? command immediately after the command execution completes(that is, do not execute other commands in the middle) to view the return value, the meaning that each return value represents is listed below.
0 Normal
1 Warning (no errors), for example, some files cannot be read during compression
2 Error
7 Unable to recognize command line arguments
8 does not have enough memory to perform the operation
255 the user presses CTRL + C to abort the program.

7-zip usages at the command line
Note: All operations without special instructions, are under the normal user operation
1. Basic operation
Compress

I put some of the documents used in the experiment under ~/TEMP, and the structure is as follows:

Contains three files, two directories, one of which is a hidden Denzo freemind directory contains two subdirectories, one of which is hidden Denzo.
OK, let's compress these files and execute them at the command line.

code:7z a temp.7z *

The effect is as follows:

Compact success
view files contained within a compressed file
See what's inside a compressed file, executable command
code:7z L temp.7z

The effect is as follows:

add files to a compressed file
As you can see, all the files and directories except. Freemind are added to the compressed file, which means that the hidden Denzo files and directories cannot be compressed directly. you can add a hidden Denzo file after compression, that is, execute the command
code:7z a temp.7z. Freemind


OK, now this hidden Denzo directory is added.
Extract Files(After installing the RAR module, you can extract rar files
Below, will compress the good file decompression, in the decompression, the general use of X or 7z x, because E does not establish the directory structure, the extracted files are directly output to the current directory, in this case, the extracted files are all placed under a specified directory T, so execute the command
code:7z X-ot temp.7z



As you can see, the directory T was created automatically, and 7zip unzipped the file as expected.
Note, decompression can not indicate the type, 7zip will automatically identify.
2. Encrypt file
To facilitate demonstrations, first delete the files and directories that were exported in the previous example.
You can use the-P argument for compressed file encryptionSuch as
code:7z a-p temp.7z *


Then ask you to enter the password, and then verify again, two times exactly the same, you can pass.
At this point and then extract the file will require you to enter the password, only the correct password can be the normal solution to the file, otherwise the output of the file is all blank files, at this time 7-zip output of 2, such as
code:7z X-ot temp.7z



Of course, you can also follow the content of the password after-p, such as-p123456, but the contents of the password will remain on the screen, there is the risk of leakage.
3. Encrypt file list
7-zip only files that are compressed using-p do not encrypt the file list, although the extract must pass the password, but the list of files can still be viewed through 7z l filename.7z, so You can add parameter-mhe=on to enable encryption of the file list, which can be used with-p (note, this method only applies to compression of the 7z format), as
code:7z a-p-mhe=on temp.7z *


At this point, you must pass the password to view the list of files. Otherwise you cannot view it, such as

4. Specify the compression level
The higher the compression level, the smaller the amount of space the compressed file occupies, but the compression/decompression process occupies a higher memory, the compression/decompression takes longer, sometimes we need to compress large files, or to compress the size of all the files are large, there may be insufficient memory to compress/decompression problems, To avoid this problem, need to adjust the compression level, the parameters to adjust the compression level are-mx=n,n 0, 1, 3, 5, 7, 9, where the 0 level is packaged and uncompressed. Here to show the effect, take a slightly larger file as an example.
First we look at the default level of compression, execute the command
code:7z a z.7z openschultetable1_x86_64


About 16MB of files were compressed into about 3MB.
And look at the highest level.
code:7z a-mx=9 z9.7z openschultetable1_x86_64


The default level is similar to the maximum size after compression (but the default level is not the highest level), then look at level 0
code:7z a-mx=0 z0.7z openschultetable1_x86_64


Level 0 compression and the size of the original file is very close, you can think of level 0 compression is only packaged, not compression.
5. Sub-volume compression
If you want to put the compressed file on the forum or on the mailbox, but due to file size limitations can not upload, how to do. 7-zip can satisfy you, the parameters for volume compression are-V, the usage is-v{size}[b|k|m|g], for example, want to divide the compressed file into each file 1MB size, you can use-v1m, such as
7z a-v1m zv.7z openschultetable1_x86_64

At this point, the maximum of each file is 1M, the problem is solved.
6. System backup
Special Note: The 7z format file itself does not store user and group information.
If used directly for system backups, the users and groups for all files in the restored system will be reset to the users and groups in which they are decompressed.
For example, I set several files in the ~/temp directory to the following permissions:

Use the following command to compress:
code:7z a temp.7z *

Then use the SU command to switch to root identity:
Code:su

Then unpack:
code:7z X-ot temp.7z


See. Although permissions remain, users and groups become users who understand the pressure and the primary group in which they are located. It is dangerous to use it directly to back up the entire system and restore it. So need to be packaged into a tar file and then compressed into a 7z format, but generally two steps can be combined, that is (note, here, first change back to ordinary users, easy to demonstrate)
Code:tar C * | 7za A-Si temp.tar.7z

Decompression how to do it. Use the following command (note, because the front has been swapped back to the normal user, here again with SU switch to root user):
Code:7za x-so temp.tar.7z | Tar XV


Well, as you can see, the user and group information is all preserved, but since this method uses the-ot parameter no longer works, it deleted the original file.
Note: The compressed command format given in man page is
Code:tar Cf-directory | 7za A-Si directory.tar.7z

But Tar's parameter F means to specify the name of the output file, and here is the output to Tar's stdout (that is, 7z stdin), so you can add the word "-" to the end without F, plus f, and the problem will arise. In the same vein, if you add parameter f to tar, you also need to add a "-" (note space) at the back, i.e.
Code:7za x-so directory.tar.7z | Tar XF-

7. About Links
By default, 7zip saves the symbolic link as-is, and now I put the structure and content of the ~/temp directory as shown in the following illustration

Now, execute the LN-S ~/temp/freemind FM command to create a link to the Freemind directory, and then compress (note, here to highlight the effect, use level 0 compression, that is, package only), execute the command
code:7z a-mx=0 temp.7z *


Use 7z X-ot temp.7z decompression, and then use Ls-l t to view

Visible The symbolic link in the compressed file is stored as a link, and then look at how hard links are stored, delete T and temp.7z First, execute the command
Code:ln freemind/openschultetable1_x86_64 Schulte
7z a-mx=0 temp.7z *
Ls-l temp.7z


Visible 7zip does not really identify the hard links, you may create two copies in your own compressed file, but you can eliminate unnecessary hard disk expenses by recognizing that two files are the same file at the high compression level.
Sometimes need Place the file/directory pointed to by the symbolic link in its own compressed file, rather than storing the original link, you need to use the-l parameter, but note: no recursive links are included in the compressed file, or an error will occur. Next, delete the Schulte and temp.7z files, and then execute the command
code:7z a-mx=0-l temp.7z *

Then enter the command ls-l to view:

At this point, the file/directory corresponding to the symbolic link is also placed in the compressed file.

The application of 7zip in graphic interface
After half a day of command, you might say, "If you can use it in a graphical interface, it would be nice." If you have file roller or Ark in your system, then congratulations, you can use 7zip in the graphical interface, and below, let's see how to use it.
First, make sure that your system contains file roller (or Ark) and 7zip (Linux version of course). Now, I put the file to be tested under ~/TEMP.
Compress
Select the file you want to add, right-click, and click Compress.


7z and. tar.7z are all used 7zip, and the. exe format is estimated to be 7zip, as if it were to create a self-extracting file, but only for Windows, the emulator is needed under Linux.

This will be the first line is the file name, the second line is the location, click on the third line of "Other options", you can set the password, you can split the file, but the file list of the encryption is not optional, everything is good, click to create.
Decompression
Decompression is better, select the files to extract, right click, in the right menu, "Use Archive Manager Open" or "Open With Ark" (different distributions may be used as a deviation)

Note: You can use this method in the graphical interface decompression rarFile, of course, you want to install the 7zip RAR module.

7-zip under the wine .
Of course, you can also use Windows 7-zip with the help of wine to achieve, installation can With the help of Playonlinux(If your distribution can be installed), so you can use the Windows version of the 7-zip.

Finally, give the publisher the advice
Recently I see a lot of Linux on the site to the RAR file release, but also see a lot of users in the Linux forum in the RAR format to publish/upload files, although the format of RAR can be used as described above to decompress, but don't forget, any software has its own scope of operation, a part of Linux can extract 7z, RAR format files, does not mean that all Linux can do, and so does other systems, Therefore, we recommend that the publishers in the ZIP format packaging, if the published files only need to be used in Linux or un*x, then try to package into a. tar.gz,. tar.bz2,. Tar or. tgz, the files that you package are as generic as possible., do not for the sake of convenience, only to get a weird format, causing unnecessary trouble to others, of course, do not put the RAR or what to compress once oh.

Resources:
This page gives more 7-zip parameters, but the authors are experimenting with windows, for informational purposes only.
Http://blog.sina.com.cn/s/blog_57206c150100nrfy.html






















































Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.