7za

最後更新: 2023-11-17

目錄

 


7-Zip (7z)

 

Install

yum install p7zip                   # 另有 p7zip-plugins @epel

apt-get install p7zip-full

 


基本應用

 

Usage:

7z <command> [<switches>...] <archive_name> [<@listfiles...>]

常用 command 如下:

  • a:  Add files to archive
  • x:  eXtract files with full paths
  • l:   List contents of archive
  • t:   Test integrity of archive

Useful Opts

  • -o{Directory}            # 設定解壓到那裡, -o 與之後接Folder, 不帶有空格
  • -v{Size}[b|k|m|g]     # Create volumes
  • -l                              # Don’t store symlinks; store the files/directories they point to
  • -mx=N                      # Level of compression: 0(Copy), 1, 3, 5, 7, 9 (Ultra)
                                    # i.e. -mx=8, -mx 相當於 -mx=9
  • -r[-|0]                      # Recurse subdirectories (CAUTION: this flag does not do what you think, avoid using it)

Example:

打包並壓縮一個整個目錄:

7z a test.7z ./test

打包目錄(不壓縮)

7za a -mx=0 docker_package.7z docker_package

Scanning the drive:
1 folder, 5 files, 244236919 bytes (233 MiB)

Creating archive: docker_package.7z

Items to compress: 6


Files read from disk: 5
Archive size: 244237204 bytes (233 MiB)
Everything is Ok

查看 zip 包內有什麼

7z l tiki-12.3.7z  | less

   Date      Time    Attr         Size   Compressed  Name
------------------- ----- ------------ ------------  ------------------------
2014-11-14 23:01:06 ....A           94     29640662  tiki-12.3/vendor/jcapture-applet/jcapture-applet/src/META-INF/.svn/all-wcprops
2014-11-14 23:01:06 ....A          278               tiki-12.3/vendor/jcapture-applet/jcapture-applet/src/META-INF/services/.svn/all-wcprops

.......................................

Attr

  • R = READONLY
  • H = HIDDEN
  • S = SYSTEM
  • A = ARCHIVE                 # Windows 的 File Default 會有 A
  • C = COMPRESSED
  • N = NOT INDEXED
  • L = Reparse Points
  • O = OFFLINE
  • P = Sparse File
  • I = Not content indexed
  • T = TEMPORARY
  • E = ENCRYPTED

解壓

7za x tiki-12.3.7z

.......................................

Extracting  tiki-12.3

Everything is Ok

Folders: 2101
Files: 16791
Size:       137347765
Compressed: 29849851

7z extract to specific folder

7z x [archive.7z] -o[output_dir]

i.e.

7z x DATA.zip -o/volume1/tmp

Everything is Ok

Size:       11038359552
Compressed: 65107236764

 


進階使用

 

Usage:

7z <command> [<switches>...] <archive_name> [<@listfiles...>]

 

Command 如下:

  • d:  Delete files from archive
  • e:  Extract files from archive (without using directory names)
  • u:  Update files to archive

fileFilter

7z e [archive.zip] -o[outputdir] [fileFilter_1] [fileFilter_2]

i.e.

7z x DATA.zip -o/volume1/tmp DATA/mydb.mdf

 


Show extraction progress of 7zip inside cmd

 

-bd

Disable progress indicator

顯示處理了幾多 Data, 不是 zip 出來的 size

781M + [Content]

-ba

# suppress headers; undocumented.
# "7-Zip (a) [64] 16.02 : Copyright (c) ..."

-bs{o|e|p}{0|1|2}

# Set output stream for output/error/progress line to disable/stdout/stderr
# Default values: o1, e2, p1

i.e.

mkdir  tmp

7z x -otmp -bsp1 s2012.iso

Scanning the drive for archives:
1 file, 4542291968 bytes (4332 MiB)

Extracting archive: s2012.iso
--
Path = s2012.iso
Type = Udf
Physical Size = 4542291968
Comment = IR3_SSS_X64FREE_EN-US_DV9
Cluster Size = 2048
Created = 2014-03-22 05:27:47

 38% 549 - sources/install.wim

-bb[0-3]

# Set output log level

  • 0             disable log(Default)
  • null / 1    show names of processed files in log
  • 2             show names of additional files that were processed internally in solid archives
  • 3             show information about "Add" / "Update" operations

ie.

# Adds *.txt files to archive.7z and shows all files that were processed.

7z a archive.7z *.txt -bb

 


Set Password

 

Encryption

AES-256 encryption

switches

  • -p{Password}          # Set Password
  • -he=[off|on]            # Enables or disables archive header encryption

Example

7z a key-backup.txt.7z key-backup.txt -p         # 問 PW

7z a key-backup.txt.7z key-backup.txt -pYOUR-PW-HERE

7z t key-backup.txt.7z

Enter password (will not be echoed):
Everything is Ok

Size:       932
Compressed: 794

 


Overwrite mode

 

For extracting

-ao[a | s | t | u ]

  • a          Overwrite All existing files without prompt.
  • s          Skip extracting of existing files.
  • u         Rename extracting file (extracting.txt -> extracting_1.txt)
  • t          Rrename existing file (existing.txt -> existing_1.txt)

 


效能

 

-m<method_parameters>

Method Parameters

-mx                     # 相當於 compression level 9 (Ultra)
                           # 7 = Method: LZMA2, Dictionary: 32 MB, MatchFinder: BT4 , Filter: BCJ
                           # 9 = Method: LZMA2, Dictionary: 64 MB, MatchFinder: BT4 , Filter: BCJ2

-ms=on               # solid archive. Default: on
                           # In solid mode, files are grouped together.
                           # These are the default limits for the solid block size: Normal: 2G, Maximum: 4G

-md=32m            # dictionary size = 32 megabytes

 


pipeline with 7za (-si, -so)

 

應用:

7-zip does not store the owner/group of the file.

方案:

壓: tar -cf - directory | 7za a -si directory.tar.7z

解: 7za x -so directory.tar.7z | tar xf -

 


Benchmark 系統

 

There are two tests:

  • Compressing with LZMA method
  • Decompressing with LZMA method

The benchmark shows a rating in MIPS (million instructions per second).

Score

https://www.7-cpu.com/

Usage

b [number_of_iterations] [-mmt{N}] [-md{N}] [-mm={Method}]

opt

  • -md{N}        Dictionary size to increase memory usage
  • -mmt{N}      number of threads
  • -mm=crc      run a CRC calculation benchmark
                       That test shows the speed of CRC calculation in MB/s.

Example

7za b

RAM size:    1006 MB,  # CPU hardware threads:   2
RAM usage:    425 MB,  # Benchmark threads:      2

Dict        Compressing          |        Decompressing
      Speed Usage    R/U Rating  |    Speed Usage    R/U Rating
       KB/s     %   MIPS   MIPS  |     KB/s     %   MIPS   MIPS

22:    4469   156   2790   4347  |    19918   131   1371   1798
23:    3100   157   2017   3159  |    19653   131   1374   1799
24:    3044   157   2078   3273  |    20536   133   1435   1905
25:    5922   179   3767   6761  |    61724   200   2899   5805
----------------------------------------------------------------
Avr:          162   2663   4385               149   1770   2827
Tot:          156   2216   3606

解說

Dict

shows dictionary size. For example, 21 means 2^21 = 2 MB.

Usage

shows the percentage of time the processor is working.

It's normalized for a one-thread load.

For example, 180% CPU Usage for 2 threads can mean that average CPU usage is about 90% for each thread.

R/U

The rating normalized for 100% of CPU usage.

That column shows the performance of one average CPU thread.

MIPS = million instructions per second

Rating

The rating value is calculated from the measured CPU speed and

  it is normalized with results of Intel Core 2 CPU with multi-threading option switched off.

rating values in single-thread mode must be close to real CPU frequency.

Remark

7-Zip 18.03 uses new optimized version of LZMA decoder for x64 (x86-64) system.

The new LZMA decoder for x64 is written in assembler and

  it uses Conditional Move (CMOV) instructions instead of branches in original code.

Compression / Decompression speed

Compression speed

strongly depends from memory (RAM) latency, Data Cache size/speed and TLB.

Out-of-Order execution feature of CPU is also important for that test.

Decompression speed

strongly depends on CPU integer operations.

The most important things for that test are:

branch misprediction penalty (the length of pipeline) and the latencies of 32-bit instructions ("multiply", "shift", "add" and other).

The decompression test has very high number of unpredictable branches.

Note that some CPU architectures (for example, 32-bit ARM) support instructions that can be conditionally executed.

So such CPUs can work without branches (and without pipeline flushing) in many cases in LZMA decompression code.

And such CPUs can have some speed advantages over other architectures that don't support complex conditionally execution.

Out-of-Order execution capability is not so important for LZMA Decompression.

 

 

Creative Commons license icon Creative Commons license icon