7z命令教程,其中包含在Linux中压缩和提取文件的示例

7zip is a popular tool and compression format. 7zip supports a wide range of platforms and operations systems like Windows, Linux, BSD, macOS, etc.

7zip是一种流行的工具和压缩格式。 7zip支持各种平台和操作系统,例如Windows,Linux,BSD,macOS等。

句法 (Syntax)

We will use following syntax for 7z command.

我们将对7z命令使用以下语法。

7z <command> [<switches>...] <archive_name> [<file_names>...]

帮帮我 (Help)

First before starting using the 7z command we can get usage and help information by using -h option. We can see that different options like adding file to archive, benchmark, delete files from archive etc. listed with the -h option output.

首先,在开始使用7z命令之前,我们可以使用-h选项获取使用情况和帮助信息。 我们可以看到-h选项输出列出了不同的选项,例如将文件添加到归档文件,进行基准测试,从归档文件中删除文件等。

$ 7z -h
Help
7z Command Line Help Information with -h Option
带-h选项的7z命令行帮助信息

Alternatively, we can list usage and help information without providing any option to the 7z command like below.

另外,我们可以列出用法和帮助信息,而无需为7z命令提供任何选项,如下所示。

$ 7z
7z Command Line Help Information
7z命令行帮助信息

7z命令(7z Commands)

While using 7z there is two-component as we can see in the syntax. One of them is commands. Commands are used to specify the operations like:

使用7z时,我们可以从语法中看到两个组成部分。 其中之一是命令。 命令用于指定类似的操作:

  •  a : Add files to archive

    a :将文件添加到存档

  •  b : Benchmark

    b :基准

  •  d : Delete files from archive

    d :从存档中删除文件

  •  e : Extract files from archive (without using directory names)

    e :从存档中提取文件(不使用目录名)

  •  h : Calculate hash values for files

    h :计算文件的哈希值

  •  i : Show information about supported formats

    i :显示有关支持的格式的信息

  •  l : List contents of archive

    l :列出档案内容

  •  rn : Rename files in archive

    rn :重命名存档中的文件

  •  t : Test integrity of archive

    t :测试档案的完整性

  •  u : Update files to archive

    u :更新文件以存档

  •  x : eXtract files with full paths

    x :具有完整路径的eXtract文件

开关(Switches)

Switches are used to specify some minor options like create SFX archive, compress shared files, set output log level. Here are some of them

开关用于指定一些次要选项,例如创建SFX存档,压缩共享文件,设置输出日志级别。 这里是其中的一些

  •   -- : Stop switches parsing

    -- :停止开关解析

  •  -ai[r[-|0]]{@listfile|!wildcard} : Include archives

    -ai[r[-|0]]{@listfile|!wildcard} :包括存档

  •  -ax[r[-|0]]{@listfile|!wildcard} : eXclude archives

    -ax[r[-|0]]{@listfile|!wildcard} :排除档案

  •  –ao{a|s|t|u} : set Overwrite mode

    ao{a|s|t|u} :设置覆盖模式

  •  -an : disable archive_name field

    -an :禁用archive_name字段

压缩文件和文件夹(Compress Files and Folders)

7z can compress files and folders. We will use a command to create a new archive. The new archive file name will be mybackup.7z and we will put files named a.out , body.txt and folder cups . Here the

7z可以压缩文件和文件夹。 我们将使用a命令来创建一个新的存档。 新的存档文件名为mybackup.7z ,我们将放置名为a.outbody.txt和文件夹cups文件。 在这里

$ 7z a mybackups.7z a.out body.txt cups
Compress Files and Folders
Compress Files and Folders
压缩文件和文件夹

Here while starting 7z applications show some information about the 7z application like build number, version, developer. And then provided files and folders are scanned and the scan result is printed like 56 folders, 1550 files, and a total 142 MB. After compression is completed new archive size is printed as 96 MB.

在启动7z应用程序时,此处显示有关7z应用程序的一些信息,例如内部版本号,版本,开发人员。 然后扫描提供的文件和文件夹,并打印扫描结果,例如56个文件夹,1550个文件和总共142 MB。 压缩完成后,新的存档大小将打印为96 MB。

将文件添加到存档 (Add Files To The Archive)

In previous example we have created the archive file. Some time we need to add new files to the existing archive file. In this situations we will use same a option to add files.

在前面的示例中,我们创建了存档文件。 一段时间后,我们需要将新文件添加到现有存档文件中。 在这种情况下,我们将使用相同a选项来添加文件。

$ 7z a mybackups.7z fruits.txt
Add Files To The Archive
Add Files To The Archive
将文件添加到存档

In this operation mybackup.7z archive file already exists. Some information about the file is printed like path, compression type, size, etc. Then a new file is added to the existing archive or compressed file named mybackup.7z .

在此操作中, mybackup.7z存档文件已存在。 打印有关文件的一些信息,例如路径,压缩类型,大小等。然后,将新文件添加到名为mybackup.7z的现有存档或压缩文件中。

LEARN MORE  How To List and Unrar Rar Files In Ubuntu, Debian, Kali, Mint?
了解更多信息如何在Ubuntu,Debian,Kali,Mint中列出和解压缩Rar文件?

从存档中删除文件 (Delete Files From Archive)

Another useful operation is removing one or more files from an existing archive file. We will use d command with the file we want to delete. In this example, we want to remove the file named fruits.txt from the archive file mybackups.7z .

另一项有用的操作是从现有存档文件中删除一个或多个文件。 我们将对要删除的文件使用d命令。 在此示例中,我们要从存档文件mybackups.7z删除名为fruits.txt的文件。

$ 7z d mybackups.7z fruits.txt
Delete Files From Archive
Delete Files From Archive
从存档中删除文件

从存档/压缩文件中提取文件(Extract Files From The Archive/Compressed File)

We can extract all files from an archive or compressed file by using x command or option. We will also provide the archive or compressed file. In this example, we will extract the mybackups.7z .

我们可以使用x命令或选项从存档文件或压缩文件中提取所有文件。 我们还将提供存档或压缩文件。 在此示例中,我们将提取mybackups.7z。

$ 7z x mybackups.7z
Extract Files
Extract Files
提取文件

As we can see from the screenshot there are some existing files which will be overwritten. There question whether we want to overwrite, skip, rename, etc. We answer this as Always. After extraction, some statistical information like total folder count, file count size, compressed size is printed.

正如我们从屏幕快照中看到的,有一些现有文件将被覆盖。 有人问我们是否要覆盖,跳过,重命名等。我们将其回答为始终。 提取后,将打印一些统计信息,例如文件夹总数,文件计数大小,压缩大小。

列出档案内容 (List Contents of Archive)

We can also list files of an archive with l command. We will list all files of mybackup.7z archive.

我们还可以使用l命令列出档案文件。 我们将列出mybackup.7z存档的所有文件。

$ 7z l mybackups.7z
List Contents of Archive
List Contents of Archive
列出档案内容

In the output, we can see that files and folders are listed. While listing information like date, time, attributes, size, and name are provided.

在输出中,我们可以看到列出了文件和文件夹。 在列出信息时,会提供日期,时间,属性,大小和名称等信息。

翻译自: https://www.poftut.com/7z-command-tutorial-examples-compress-extract-files-linux/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值