admin管理员组

文章数量:1596328

文章目录

    • 常见压缩文件后缀
    • 常见压缩/解压工具
      • 常见方法
  • 详解
    • tar
      • tar 分卷压缩/解压
      • SCHILY.fflags 报错
    • rar
      • rar 分卷压缩
      • macOS 安装 rar/unrar
    • zip
    • unzip
    • zipinfo
    • gzip
    • bzip2
    • 7z
      • 安装
      • 7z 分卷压缩
      • manual


常见压缩文件后缀

  • .zip ,是. Windows中最常用的压缩格式,Linux 也可以正确识别.zip 格式,这可以方便地和Windows系统通用压缩文件。
    使用 zip 命令压缩, unzip 命令解压
  • .gz ,是Linux中最常用的压缩格式;
    使用 gzip 命令进行压缩,可以压缩文件和目录
  • .tar 格式打包和解打包都使用 tar 命令。
  • .tar.gz.tgz, 用 tar –xzf 解压
  • .tar.bz2,用 tar –xjf 解压
  • .tar.Ztar –xZf 解压
  • .bz2 格式是Linux的一种压缩格式。理论上来讲.bz2 格式的算法比 .gz 更先进、压缩比更好;而.gz 格式相对来讲压缩的时间更快。
    可以使用 bzip2 压缩,bunzip2 解压
  • .rar,使用 用 unrar e解压
  • *.Z 用 uncompress 解压

常见压缩/解压工具

常用压缩命令行工具

  • zip
  • unzip
  • tar
  • bzip2

常见方法

# 压缩成 .tar
tar -cvf file.tar  file
tar -zcvf  a.tgz source_dir

# 解压(到当前目录
tar -xvf file.tar

# 解压到指定目录
tar -zxvf examples.tar -C target_dir

# 压缩成 .tgz:	
tar -zcvf file.tgz  file
# 解压
tar -zxvf file.tgz

# 压缩成 .gzip:	
gzip -r examples.gz source_dir
# 解压
gunzip -r examples.gz

# 将 source_dir 文件夹压缩为 a.zip 文件 (-r 递归处理
zip -r a.zip source_dir  

# 解压到 target_dir 目录下
unzip a.zip  -d target_dir

# 查看压缩包 内容 
unzip -l a.zip 

# 压缩成 .rar:	
rar -a examples.rar source_dir
# 解压
unrar examples.rar 

详解

tar

$ tar -h
tar(bsdtar): manipulate archive files

First option must be a mode specifier:
  -c Create  -r Add/Replace  -t List  -u Update  -x Extract
  
Common Options:
  -b #  Use # 512-byte records per I/O block
  -f <filename>  Location of archive
  -v    Verbose
  -w    Interactive
  
Create: tar -c [options] [<file> | <dir> | @<archive> | -C <dir> ]
  <file>, <dir>  add these items to archive
  -z, -j, -J, --lzma  Compress archive with gzip/bzip2/xz/lzma
  --format {ustar|pax|cpio|shar}  Select archive format
  --exclude <pattern>  Skip files that match pattern
  -C <dir>  Change to <dir> before processing remaining files
  @<archive>  Add entries from <archive> to output

List: tar -t [options] [<patterns>]
  <patterns>  If specified, list only entries that match
  
Extract: tar -x [options] [<patterns>]
  <patterns>  If specified, extract only entries that match
  -k    Keep (don't overwrite) existing files
  -m    Don't restore modification times
  -O    Write entries to stdout, don't restore to disk
  -p    Restore permissions (including ACLs, owner, file flags)
  
bsdtar 3.5.1 - libarchive 3.5.1 zlib/1.2.11 liblzma/5.0.5 bz2lib/1.0.8 


选项简述

  • -c:打包
  • -x:解包
  • -f:Location of archive,指定压缩包的文件名。压缩包的扩展名是用来给管理员识别格式的,所以一定要正确指定扩展名。
  • -v:Verbose,显示打包文件过程
  • -t:测试,不解打包,只是查看包中有哪些文件
  • -z、--gzip:调用gzip对tar包进行压缩
  • -z:压缩和解压缩.tar.gz 格式
  • -j:压缩和解压缩.tar.bz2 格式
  • -w, Interactive

tar 分卷压缩/解压

tar cvzf - src_dir/ | split -d -b 15m - dirname.tar.gz
  • src_dir/ 目标文件夹
  • 15m 一个压缩包
  • 最多生成 100个文件,从 *.tar.gz00*.tar.gz99
  • 单位为 k,m; 不能是 0.2m,可以是500k;

# 合并分卷文件
cat dirname.tar.* > dirname_all.tar

# 解压缩
tar xzvf  dirname_all.tar 

# 查看压缩包内容
tar -tf  a.tar 

SCHILY.fflags 报错

linux 上出现下述问题:

tar: Ignoring unknown extended header keyword `SCHILY.fflags

原因:可能是因为在 macOS 上压缩会加入一些内容
解决方式:使用 bsdtar 替代 tar 来


安装 bsdtar

sudo apt install bsdtar
sudo yum install bsdtar

解压

bsdtar a.tar -C target_dir

rar

$ unrar --help
Usage: unrar [OPTION...] ARCHIVE [FILE...] [DESTINATION]
Extract files from rar archives.

  -x, --extract              Extract files from archive (default)
  -t, --list                 List files in archive
  -f, --force                Overwrite files when extracting
      --extract-newer        Only extract newer files from the archive
      --extract-no-paths     Don't create directories while extracting
  -p, --password             Decrypt archive using a password
  -?, --help                 Give this help list
      --usage                Give a short usage message
  -V, --version              Print program version

Report bugs to <benasselstine@canada>.

# 安装
sudo apt install rar

# 压缩
rar -a a.rar a_dir
 
# 解压
rar -x a.rar
unrar a.rar 

rar 分卷压缩

将文件夹 10 压缩

$ rar a -v10k a.rar 10/

RAR 6.22   Copyright (c) 1993-2023 Alexander Roshal   29 May 2023
Trial version             Type 'rar -?' for help

Evaluation copy. Please register.

Creating archive a.rar

Adding    10/01.txt                                                   OK 
Adding    10/.DS_Store                                                OK 
Adding    10/sample.txt                                

Creating archive a.part2.rar

...       10/sample.txt                                

Creating archive a.part3.rar

...       10/sample.txt                                

Creating archive a.part4.rar

...       10/sample.txt                             OK 
Done 
 

生成压缩文件:a.part1.rar , a.part2.rar, a.part3.rar, a.part4.rar


解压
和 tar 的分卷文件不同。tar 需要将分卷的文件,cat 成一个文件;rar 则只需要解压其中一个就好。解压任意一个,得到的效果相同。

这里使用 rar e 而非 unrar

rar e a.part2.rar 

macOS 安装 rar/unrar

brew install rar
brew install unrar
  • rar : https://www.rarlab

zip

$ zip -h
Copyright (c) 1990-2008 Info-ZIP - Type 'zip "-L"' for software license.
Zip 3.0 (July 5th 2008). Usage:
zip [-options] [-b path] [-t mmddyyyy] [-n suffixes] [zipfile list] [-xi list]
  
The default action is to add or replace zipfile entries from list, which can include the special name - to compress standard input.
If zipfile and list are omitted, zip compresses stdin to stdout.
  • -f, freshen: only changed files -u update: only changed or new files
  • -d, delete entries in zipfile
  • -m, move into zipfile (delete OS files)
  • -r, recurse into directories
  • -j, junk (don’t record) directory names
  • -0, store only
  • -l, convert LF to CR LF (-ll CR LF to LF)
  • -1, compress faster
  • -9, compress better
  • -q, quiet operation
  • -v, verbose operation/print version info
  • -c, add one-line comments
  • -z, add zipfile comment
  • -@, read names from stdin
  • -o, make zipfile as old as latest entry
  • -x, exclude the following names
  • -i, include only the following names
  • -F, fix zipfile (-FF try harder)
  • -D, do not add directory entries
  • -A, adjust self-extracting exe
  • -J, junk zipfile prefix (unzipsfx)
  • -T, test zipfile integrity
  • -X, eXclude eXtra file attributes
  • -y, store symbolic links as the link instead of the referenced file
  • -e, encrypt
  • -n, don’t compress these suffixes
  • -h2, show more help

查看文件内容(不解压)

$ zip -sf xx.zip 
Archive contains:
  a0.txt
Total 1 entries (1226063315 bytes)

unzip

# 解压部分文件
unzip <Your zip file>  "*mobile/要解压的文件" -d <要解压的目录>`

unzip -j a.zip  "*/文件名.后缀" 
# -d 目标文件夹名字 
# -j会忽略掉所有的目录结构
# -o或覆盖掉已存在的文件



manual

$ unzip -hh

Extended Help for UnZip

See the UnZip Manual for more detailed help


UnZip lists and extracts files in zip archives.  The default action is to
extract zipfile entries to the current directory, creating directories as
needed.  With appropriate options, UnZip lists the contents of archives
instead.

Basic unzip command line:
  unzip [-Z] options archive[.zip] [file ...] [-x xfile ...] [-d exdir]

Some examples:
  unzip -l foo.zip        - list files in short format in archive foo.zip

  unzip -t foo            - test the files in archive foo

  unzip -Z foo            - list files using more detailed zipinfo format

  unzip foo               - unzip the contents of foo in current dir

  unzip -a foo            - unzip foo and convert text files to local OS

If unzip is run in zipinfo mode, a more detailed list of archive contents
is provided.  The -Z option sets zipinfo mode and changes the available
options.

Basic zipinfo command line:
  zipinfo options archive[.zip] [file ...] [-x xfile ...]
  unzip -Z options archive[.zip] [file ...] [-x xfile ...]

Below, Mac OS refers to Mac OS before Mac OS X.  Mac OS X is a Unix based
port and is referred to as Unix Apple.


unzip options:
  -Z   Switch to zipinfo mode.  Must be first option.
  -hh  Display extended help.
  -A   [OS/2, Unix DLL] Print extended help for DLL.
  -c   Extract files to stdout/screen.  As -p but include names.  Also,
         -a allowed and EBCDIC conversions done if needed.
  -f   Freshen by extracting only if older file on disk.
  -l   List files using short form.
  -p   Extract files to pipe (stdout).  Only file data is output and all
         files extracted in binary mode (as stored).
  -t   Test archive files.
  -T   Set timestamp on archive(s) to that of newest file.  Similar to
       zip -o but faster.
  -u   Update existing older files on disk as -f and extract new files.
  -v   Use verbose list format.  If given alone as unzip -v show version
         information.  Also can be added to other list commands for more
         verbose output.
  -z   Display only archive comment.

unzip modifiers:
  -a   Convert text files to local OS format.  Convert line ends, EOF
         marker, and from or to EBCDIC character set as needed.
  -b   Treat all files as binary.  [Tandem] Force filecode 180 ('C').
         [VMS] Autoconvert binary files.  -bb forces convert of all files.
  -B   [UNIXBACKUP compile option enabled] Save a backup copy of each
         overwritten file in foo~ or foo~99999 format.
  -C   Use case-insensitive matching.
  -D   Skip restoration of timestamps for extracted directories.  On VMS this
         is on by default and -D essentially becames -DD.
  -DD  Skip restoration of timestamps for all entries.
  -E   [MacOS (not Unix Apple)]  Display contents of MacOS extra field during
         restore.
  -F   [Acorn] Suppress removal of NFS filetype extension.  [Non-Acorn if
         ACORN_FTYPE_NFS] Translate filetype and append to name.
  -i   [MacOS] Ignore filenames in MacOS extra field.  Instead, use name in
         standard header.
  -j   Junk paths and deposit all files in extraction directory.
  -J   [BeOS] Junk file attributes.  [MacOS] Ignore MacOS specific info.
  -K   [AtheOS, BeOS, Unix] Restore SUID/SGID/Tacky file attributes.
  -L   Convert to lowercase any names from uppercase only file system.
  -LL  Convert all files to lowercase.
  -M   Pipe all output through internal pager similar to Unix more(1).
  -n   Never overwrite existing files.  Skip extracting that file, no prompt.
  -N   [Amiga] Extract file comments as Amiga filenotes.
  -o   Overwrite existing files without prompting.  Useful with -f.  Use with
         care.
  -P p Use password p to decrypt files.  THIS IS INSECURE!  Some OS show
         command line to other users.
  -q   Perform operations quietly.  The more q (as in -qq) the quieter.
  -s   [OS/2, NT, MS-DOS] Convert spaces in filenames to underscores.
  -S   [VMS] Convert text files (-a, -aa) into Stream_LF format.
  -U   [UNICODE enabled] Show non-local characters as #Uxxxx or #Lxxxxxx ASCII
         text escapes where x is hex digit.  [Old] -U used to leave names
         uppercase if created on MS-DOS, VMS, etc.  See -L.
  -UU  [UNICODE enabled] Disable use of stored UTF-8 paths.  Note that UTF-8
         paths stored as native local paths are still processed as Unicode.
  -V   Retain VMS file version numbers.
  -W   [Only if WILD_STOP_AT_DIR] Modify pattern matching so ? and * do not
         match directory separator /, but ** does.  Allows matching at specific
         directory levels.
  -X   [VMS, Unix, OS/2, NT, Tandem] Restore UICs and ACL entries under VMS,
         or UIDs/GIDs under Unix, or ACLs under certain network-enabled
         versions of OS/2, or security ACLs under Windows NT.  Can require
         user privileges.
  -XX  [NT] Extract NT security ACLs after trying to enable additional
         system privileges.
  -Y   [VMS] Treat archived name endings of .nnn as VMS version numbers.
  -$   [MS-DOS, OS/2, NT] Restore volume label if extraction medium is
         removable.  -$$ allows fixed media (hard drives) to be labeled.
  -/ e [Acorn] Use e as extension list.
  -:   [All but Acorn, VM/CMS, MVS, Tandem] Allow extract archive members into
         locations outside of current extraction root folder.  This allows
         paths such as ../foo to be extracted above the current extraction
         directory, which can be a security problem.
  -^   [Unix] Allow control characters in names of extracted entries.  Usually
         this is not a good thing and should be avoided.
  -2   [VMS] Force unconditional conversion of names to ODS-compatible names.
         Default is to exploit destination file system, preserving cases and
         extended name characters on ODS5 and applying ODS2 filtering on ODS2.


Wildcards:
  Internally unzip supports the following wildcards:
    ?       (or %% or #, depending on OS) matches any single character
    *       matches any number of characters, including zero
    [list]  matches char in list (regex), can do range [ac-f], all but [!bf]
  If port supports [], must escape [ as [[]
  For shells that expand wildcards, escape (\* or "*") so unzip can recurse.

Include and Exclude:
  -i pattern pattern ...   include files that match a pattern
  -x pattern pattern ...   exclude files that match a pattern
  Patterns are paths with optional wildcards and match paths as stored in
  archive.  Exclude and include lists end at next option or end of line.
    unzip archive -x pattern pattern ...

Multi-part (split) archives (archives created as a set of split files):
  Currently split archives are not readable by unzip.  A workaround is
  to use zip to convert the split archive to a single-file archive and
  use unzip on that.  See the manual page for Zip 3.0 or later.

Streaming (piping into unzip):
  Currently unzip does not support streaming.  The funzip utility can be
  used to process the first entry in a stream.
    cat archive | funzip

Testing archives:
  -t        test contents of archive
  This can be modified using -q for quieter operation, and -qq for even
  quieter operation.

Unicode:
  If compiled with Unicode support, unzip automatically handles archives
  with Unicode entries.  Currently Unicode on Win32 systems is limited.
  Characters not in the current character set are shown as ASCII escapes
  in the form #Uxxxx where the Unicode character number fits in 16 bits,
  or #Lxxxxxx where it doesn't, where x is the ASCII character for a hex
  digit.


zipinfo options (these are used in zipinfo mode (unzip -Z ...)):
  -1  List names only, one per line.  No headers/trailers.  Good for scripts.
  -2  List names only as -1, but include headers, trailers, and comments.
  -s  List archive entries in short Unix ls -l format.  Default list format.
  -m  List in long Unix ls -l format.  As -s, but includes compression %.
  -l  List in long Unix ls -l format.  As -m, but compression in bytes.
  -v  List zipfile information in verbose, multi-page format.
  -h  List header line.  Includes archive name, actual size, total files.
  -M  Pipe all output through internal pager similar to Unix more(1) command.
  -t  List totals for files listed or for all files.  Includes uncompressed
        and compressed sizes, and compression factors.
  -T  Print file dates and times in a sortable decimal format (yymmdd.hhmmss)
        Default date and time format is a more human-readable version.
  -U  [UNICODE] If entry has a UTF-8 Unicode path, display any characters
        not in current character set as text #Uxxxx and #Lxxxxxx escapes
        representing the Unicode character number of the character in hex.
  -UU [UNICODE]  Disable use of any UTF-8 path information.
  -z  Include archive comment if any in listing.


funzip stream extractor:
  funzip extracts the first member in an archive to stdout.  Typically
  used to unzip the first member of a stream or pipe.  If a file argument
  is given, read from that file instead of stdin.

funzip command line:
  funzip [-password] [input[.zip|.gz]]


unzipsfx self extractor:
  Self-extracting archives made with unzipsfx are no more (or less)
  portable across different operating systems than unzip executables.
  In general, a self-extracting archive made on a particular Unix system,
  for example, will only self-extract under the same flavor of Unix.
  Regular unzip may still be used to extract embedded archive however.

unzipsfx command line:
  <unzipsfx+archive_filename>  [-options] [file(s) ... [-x xfile(s) ...]]

unzipsfx options:
  -c, -p - Output to pipe.  (See above for unzip.)
  -f, -u - Freshen and Update, as for unzip.
  -t     - Test embedded archive.  (Can be used to list contents.)
  -z     - Print archive comment.  (See unzip above.)

unzipsfx modifiers:
  Most unzip modifiers are supported.  These include
  -a     - Convert text files.
  -n     - Never overwrite.
  -o     - Overwrite without prompting.
  -q     - Quiet operation.
  -C     - Match names case-insensitively.
  -j     - Junk paths.
  -V     - Keep version numbers.
  -s     - Convert spaces to underscores.
  -$     - Restore volume label.

If unzipsfx compiled with SFX_EXDIR defined, -d option also available:
  -d exd - Extract to directory exd.
By default, all files extracted to current directory.  This option
forces extraction to specified directory.

See unzipsfx manual page for more information.

zipinfo

$ zipinfo --help
ZipInfo 3.00 of 20 April 2009, by Greg Roelofs and the Info-ZIP group.

List name, date/time, attribute, size, compression method, etc., about files
in list (excluding those in xlist) contained in the specified .zip archive(s).
file[.zip] may be a wildcard name containing *, ?, [] (e.g., "[a-j]*.zip").


usage:

zipinfo [-12smlvChMtTz] file[.zip] [list…] [-x xlist…]
or:
unzip -Z [-12smlvChMtTz] file[.zip] [list…] [-x xlist…]


main listing-format options:

  • -s, short Unix ls -l format (def.)
  • -1, filenames ONLY, one per line | 只列出文件名称。
  • -m, medium Unix ls -l format
  • -2, just filenames but allow -h/-t/-z- | 此参数的效果和指定 -1 参数类似,但可搭配 -h, -t-z 参数使用。
  • -l, long Unix ls -l format | 此参数的效果和指定 -m 参数类似,但会列出原始文件的大小而非每个文件的压缩率。
  • -v, verbose, multi-page format miscellaneous options:
  • -h, print header line | 只列出压缩文件的文件名称。
  • -t, print totals for listed files or for all
  • -z, print zipfile comment
  • -T, print file times in sortable decimal format
  • -C, be case-insensitive
  • -M, page output through built-in “more”
  • -x, exclude filenames that follow from listing

使用示例

不解压,查看压缩包内容

$ zipinfo -1 -M   xxx.zip 
a.txt

gzip

gzip 是 GNUzip 的缩写。

gzip只能压缩文件,不能打包(文件夹)。可以将该目录下的所有文件分别压缩为 .gz


命令选项简述

  • -z, --gzip 通过 gzip 压缩的形式对文件进行归档
  • -6 指定 压缩效率,默认为6,范围1到9。1的压缩效率最小 压缩速度最快,9反之。
  • -c:将压缩数据输出到标准输出中,可以用于保留源文件
  • -d, --decompress, uncompress files | 将压缩文件解压
  • -l, --list, list compressed file contents | 对每个压缩文件,显示下列字段: 压缩文件的大小;未压缩文件的大小;压缩比;未压缩文件的名字
  • -r, --recursive, recursively compress files in directories | 递归式地查找指定目录并压缩其中的所有文件或者是解压缩。
  • -t, --test, test compressed file | 测试,检查压缩文件是否完整。
  • -V, --version, display program version
  • -v, --verbose, print extra statistics | 对每一个压缩和解压的文件,显示文件名和压缩比。

使用 示例

gzip -r -6 examples.gz examples
gzip   -dr examples.gz 
gunzip -r  examples.gz

# 把当前目录下的每个文件压缩成 .gz 文件。
gzip *

# 把当前目录下每个压缩的文件解压,并列出详细的信息。
gzip -dv *

# 详细显示例1中每个压缩的文件的信息,并不解压。
gzip -l *

# 压缩 tar 备份文件 usr.tar,此时压缩文件的扩展名为.tar.gz。
gzip usr.tar


linux

$ gzip -h
Usage: gzip [OPTION]... [FILE]...
Compress or uncompress FILEs (by default, compress FILES in-place).

Mandatory arguments to long options are mandatory for short options too.

  -c, --stdout      write on standard output, keep original files unchanged
  -d, --decompress  decompress
  -f, --force       force overwrite of output file and compress links
  -h, --help        give this help
  -k, --keep        keep (don't delete) input files
  -l, --list        list compressed file contents
  -L, --license     display software license
  -n, --no-name     do not save or restore the original name and time stamp
  -N, --name        save or restore the original name and time stamp
  -q, --quiet       suppress all warnings
  -r, --recursive   operate recursively on directories
  -S, --suffix=SUF  use suffix SUF on compressed files
  -t, --test        test compressed file integrity
  -v, --verbose     verbose mode
  -V, --version     display version number
  -1, --fast        compress faster
  -9, --best        compress better
  --rsyncable       Make rsync-friendly archive

With no FILE, or when FILE is -, read standard input.

Report bugs to <bug-gzip@gnu>.

macOS

$ gzip -h
Apple gzip 353.100.22
usage: gzip [-123456789acdfhklLNnqrtVv] [-S .suffix] [<file> [<file> ...]]
 -1 --fast            fastest (worst) compression
 -2 .. -8             set compression level
 -9 --best            best (slowest) compression
 -c --stdout          write to stdout, keep original files
    --to-stdout
 -d --decompress      uncompress files
    --uncompress
 -f --force           force overwriting & compress links
 -h --help            display this help
 -k --keep            don't delete input files during operation
 -l --list            list compressed file contents
 -N --name            save or restore original file name and time stamp
 -n --no-name         don't save original file name or time stamp
 -q --quiet           output no warnings
 -r --recursive       recursively compress files in directories
 -S .suf              use suffix .suf instead of .gz
    --suffix .suf
 -t --test            test compressed file
 -V --version         display program version
 -v --verbose         print extra statistics

bzip2

bzip 原意:a block-sorting file compressor
bunzip2 原意:ablock sorting file compressor

  • -d:解压缩
  • -k:压缩时保留源文件
  • -v:显示压缩的详细信息

linux / macOS

$ bzip2 -h
bzip2, a block-sorting file compressor.  Version 1.0.8, 13-Jul-2019.

If invoked as `bzip2', default action is to compress.
           as `bunzip2',  default action is to decompress.
           as `bzcat', default action is to decompress to stdout.

If no file names are given, bzip2 compresses or decompresses from standard input to standard output.  
You can combine short flags, so `-v -4' means the same as -v4 or -4v, &c.

bzip2 [flags and input files in any order]

  • -h, --help, print this message
  • -d, --decompress, force decompression
  • -z, --compress, force compression
  • -k, --keep, keep (don’t delete) input files
  • -f, --force, overwrite existing output files
  • -t, --test, test compressed file integrity
  • -c, --stdout, output to standard out
  • -q, --quiet, suppress noncritical error messages
  • -v, --verbose, be verbose (a 2nd -v gives more)
  • -L, --license, display software version & license
  • -V, --version, display software version & license
  • -s, --small, use less memory (at most 2500k)
  • -1 .. -9, set block size to 100k … 900k
  • --fast, alias for -1
  • --best, alias for -9

7z

压缩并加密文件:

7z a -p[密码] -mx=[压缩级别] [压缩文件名].7z [待压缩文件或目录名]

# 普通解压
7z  x  your-file.zip
 
# 添加密码来解压,密码为 PASSWORD
7z  x  -pPASSWORD  your-file.zip

7z a -p123456 -mx=9 test.7z /Users/username/Desktop/test/

# 带密码解压
7z x -p123456 test.7z


安装

macOS 安装 7z

brew install p7zip

linux 安装 7z

# 安装全版本的 7zip.
sudo apt-get install p7zip-full

7z 分卷压缩

压缩

7z a a.7z /Users/luyi/Desktop/01/001.txt  -v5k

得到文件: a.7z.001, a.7z.002, a.7z.003, a.7z.004, a.7z.005


解压
和 rar 类型,和 tar 不同,解压一个文件就可以

7z x a.7z.001

manual

$ 7z -h

7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,64 bits,48 CPUs Intel(R) Xeon(R) CPU E5-2650 v4 @ 2.20GHz (406F1),ASM,AES-NI)

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

<Commands>
  a : Add files to archive
  b : Benchmark
  d : Delete files from archive
  e : Extract files from archive (without using directory names)
  h : Calculate hash values for files
  i : Show information about supported formats
  l : List contents of archive
  rn : Rename files in archive
  t : Test integrity of archive
  u : Update files to archive
  x : eXtract files with full paths

<Switches>
  -- : Stop switches parsing
  -ai[r[-|0]]{@listfile|!wildcard} : Include archives
  -ax[r[-|0]]{@listfile|!wildcard} : eXclude archives
  -ao{a|s|t|u} : set Overwrite mode
  -an : disable archive_name field
  -bb[0-3] : set output log level
  -bd : disable progress indicator
  -bs{o|e|p}{0|1|2} : set output stream for output/error/progress line
  -bt : show execution time statistics
  -i[r[-|0]]{@listfile|!wildcard} : Include filenames
  -m{Parameters} : set compression Method
    -mmt[N] : set number of CPU threads
  -o{Directory} : set Output directory
  -p{Password} : set Password
  -r[-|0] : Recurse subdirectories
  -sa{a|e|s} : set Archive name mode
  -scc{UTF-8|WIN|DOS} : set charset for for console input/output
  -scs{UTF-8|UTF-16LE|UTF-16BE|WIN|DOS|{id}} : set charset for list files
  -scrc[CRC32|CRC64|SHA1|SHA256|*] : set hash function for x, e, h commands
  -sdel : delete files after compression
  -seml[.] : send archive by email
  -sfx[{name}] : Create SFX archive
  -si[{name}] : read data from stdin
  -slp : set Large Pages mode
  -slt : show technical information for l (List) command
  -snh : store hard links as links
  -snl : store symbolic links as links
  -sni : store NT security information
  -sns[-] : store NTFS alternate streams
  -so : write data to stdout
  -spd : disable wildcard matching for file names
  -spe : eliminate duplication of root folder for extract command
  -spf : use fully qualified file paths
  -ssc[-] : set sensitive case mode
  -ssw : compress shared files
  -stl : set archive timestamp from the most recently modified file
  -stm{HexMask} : set CPU thread affinity mask (hexadecimal number)
  -stx{Type} : exclude archive type
  -t{Type} : Set type of archive
  -u[-][p#][q#][r#][x#][y#][z#][!newArchiveName] : Update options
  -v{Size}[b|k|m|g] : Create volumes
  -w[{path}] : assign Work directory. Empty path means a temporary directory
  -x[r[-|0]]{@listfile|!wildcard} : eXclude filenames
  -y : assume Yes on all queries

相关教程博客

  • Linux下rar命令详解
    http://www.nndssk/xtwt/156564CixNTH.html

2023-05-16

本文标签: 分卷tarRARzip