7z_常用命令

命令格式

1
Usage: 7zz <command> [<switches>...] <archive_name> [<file_names>...] [@listfile]

安装

将7zz文件移动到系统的bin目录
sudo cp 7zz /usr/local/bin/7zz
并且确保/usr/local/bin在系统PATH中
打开或创建.zshrc(如果你使用zsh)或.bash_profile(如果你使用bash)文件:
确认有如下内容(如果没有,请添加):
export PATH="/usr/local/bin:$PATH"
保存并关闭文件,然后执行以下命令使更改生效:
source ~/.zshrc~/.bash_profile

command(必须)

Command Description
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
  1. a是代表压缩文件到压缩包
  2. e中的“without using directory names”表示的是解压缩后的文件将不会有文件夹一级的目录,而是全部为零散的文件。
  3. x代表解压缩文件,解压缩后有压缩包中原来的文件夹。

switches(可选)

下面只列出了常用的。

Switches Description
-m{Parameters} set compression Method
-mmt[N] set number of CPU threads
-mx[N] set compression level: -mx1 (fastest) … -mx9 (ultra)
-o{Directory} set Output directory
-p{Password} set Password
-slt show technical information for l (List) command
-snh store hard links as links
-snl store symbolic links as links
-ssp do not change Last Access Time of source files while archiving
-stx{Type} exclude archive type
-t{Type} Set type of archive
-y assume Yes on all queries
注意,它给出的形式是形如这种的:-o{Directory}-o和后面的参数名是没有空格间隙的,否则无法识别。

现在比如说,我想要解压缩QuickGeometryUI.zip到当前目录下的dir文件夹(未创建):

1
7zz x QuickGeometryUI.zip -odir

我想要压缩当前目录所有文件(a、b、.test)到my7zip

1
7zz a my7zip *

结果是:

  1. 只压缩了a、b,隐藏文件没有,因为*不会通配隐藏文件。
  2. 压缩包名字自动带上了后缀my7zip.7z
    所以,如果想要压缩包含隐藏文件,建议将其作为整个文件夹(放到了Test7zip目录中)压缩。
1
7zz a my7zip Test7zip