如何在 Ubuntu 和其他 Linux 发行版上使用 7Zip
7zip 7z

> 
> 不能在 Linux 中提取 .7z 文件？学习如何在 Ubuntu 和其他 Linux 发行版中安装和使用 7zip。
> 
> 
> 


![](/data/attachment/album/201905/14/154515xqy7nbq6eyjzu7qj.jpg)


[7Zip](https://www.7-zip.org/)（更适当的写法是 7-Zip）是一种在 Windows 用户中广泛流行的归档格式。一个 7Zip 归档文件通常以 .7z 扩展结尾。它大部分是开源的，除了包含一些少量解压 rar 文件的代码。


默认大多数 Linux 发行版不支持 7Zip。如果你试图提取它，你会看见这个错误：



> 
> 不能打开这种文件类型
> 
> 
> 没有已安装的适用 7-zip 归档文件的命令。你想搜索一个命令来打开这个文件吗？
> 
> 
> 


![](/data/attachment/album/201905/14/155501xzl2lnf4ekgvk4bf.png)


不要担心，你可以轻松的在 Ubuntu 和其他 Linux 发行版中安装 7zip。


一个问题是你会注意到如果你试图用 [apt-get install 命令](https://itsfoss.com/apt-get-linux-guide/)，你会发现没有以 7zip 开头的候选安装。因为在 Linux 中 7Zip 包的名字是 [p7zip](https://sourceforge.net/projects/p7zip/)。以字母 “p” 开头而不是预期的数字 “7”。


让我们看一下如何在 Ubuntu 和其他 Linux 发行版中安装 7zip。


### 在 Ubuntu Linux 中安装 7Zip


你需要做的第一件事是安装 p7zip 包。你会在 Ubuntu 中发现 3 个包：p7zip、p7zip-full 和 pzip-rar。


pzip 和 p7zip-full 的不同是 pzip 是一个轻量级的版本，仅仅对 .7z 文件提供支持，而 p7zip-full 提供了更多的 7z 压缩算法（例如音频文件）。


p7zip-rar 包在 7z 中提供了对 [RAR 文件](https://itsfoss.com/use-rar-ubuntu-linux/) 的支持


在大多数情况下安装 p7zip-full 就足够了，但是你可能想安装 p7zip-rar 来支持 rar 文件的解压。


p7zip 包在 [Ubuntu 的 universe 仓库](https://itsfoss.com/ubuntu-repositories/) 因此保证你可以使用以下命令：



```
sudo add-apt-repository universe
sudo apt update
```

在 Ubuntu 和基于 Debian 的发行版中使用以下命令。



```
sudo apt install p7zip-full p7zip-rar
```

这很好。现在在你的系统就有了 7zip 归档的支持。


### 在 Linux 中提取 7Zip 归档文件


安装了 7Zip 后，在 Linux 中，你可以在图形用户界面或者 命令行中提取 7zip 文件。


在图形用户界面，你可以像提取其他压缩文件一样提取 .7z 文件。右击文件来提取它。


在终端中，你可以使用下列命令提取 .7z 归档文件：



```
7z e file.7z
```

### 在 Linux 中压缩文件为 7zip 归档格式


你可以在图形界面压缩文件为 7zip 归档格式。简单的在文件或目录上右击，选择“压缩”。你应该看到几种类型的文件格式选项。选择 .7z。


![7zip Archive Ubuntu](/data/attachment/album/201905/14/155503pywvbydeowybyeke.png)


作为替换，你也可以在命令行中使用。这里是你可以用来压缩的命令：



```
7z a 输出的文件名 要压缩的文件
```

默认，归档文件有 .7z 扩展。你可以通过在指定输出文件扩展名为 .zip 以压缩为 zip 格式。


### 总结


就是这样。看，在 Linux 中使用 7zip 多简单？我希望你喜欢这个快速指南。如果你有问题或者建议，请随意在下方评论让我知道。




---


via: <https://itsfoss.com/use-7zip-ubuntu-linux/>


作者：[Abhishek Prakash](https://itsfoss.com/author/abhishek/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[warmfrog](https://github.com/warmfrog) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
![Warp Terminal](/assets/images/warp-terminal.webp)


![Warp Terminal](/assets/images/warp-terminal.webp)

[7Zip](https://www.7-zip.org/?ref=itsfoss.com) (properly written as 7-Zip) is an archive format hugely popular among Windows users. A 7Zip archive file usually ends in .7z extension. It’s mostly an open source software, barring a few parts of the code that deals with [unRAR](https://itsfoss.com/use-rar-ubuntu-linux/).

The 7Zip support is not enabled by default in most Linux distributions. If you try to extract it, you may see this error:


**Could not open this file type**

**There is no command installed for 7-zip archive files. Do you want to search for a command to open this file?**![There is no command installed for 7-zip archive files](https://itsfoss.com/content/images/wordpress/2015/07/Install_7zip_ubuntu_1.png)

Don’t worry, you can easily install 7zip in Ubuntu or other Linux distributions.

The one problem you’ll notice if you try to use the [apt-get install command](https://itsfoss.com/apt-get-linux-guide/), you’ll see that there are no installation candidates that start with 7zip. It’s because the 7Zip package in Linux is named [p7zip](https://sourceforge.net/projects/p7zip/?ref=itsfoss.com), starting with the letter ‘p’ instead of the expected number ‘7’.

Let’s see how to install 7zip in Ubuntu and (possibly) other Linux distributions.

## Install 7Zip in Ubuntu Linux

The first thing you need is to install the p7zip package. You’ll find three 7zip packages in Ubuntu:

- p7zip
- p7zip-full
- p7zip-rar.

The difference between *p7zip* and *p7zip-full* is that *p7zip* is a lighter version providing support only for .7z while the full version provides support for more 7z compression algorithms (for audio files etc.).

The p7zip-rar package provides support for [RAR files](https://itsfoss.com/use-rar-ubuntu-linux/) along with 7z.

Installing *p7zip-full* should be sufficient in most cases, but you may also install *p7zip-rar* for additional support for the RAR file.

p7zip packages are in the [universe repository in Ubuntu](https://itsfoss.com/ubuntu-repositories/) so make sure that you have enabled it using this command:

```
sudo add-apt-repository universe
sudo apt update
```


Use the following command to install 7zip support in Ubuntu and Debian based distributions.

`sudo apt install p7zip-full p7zip-rar`


That’s good. Now you have 7zip archive support in your system.

## Extract 7Zip archive file in Linux

With 7Zip installed, you can either use the GUI or the command line to extract 7zip files in Linux.

In the terminal, you can extract a .7z archive file using this command:

`7z e file.7z`


In the GUI, you can extract a .7z file as you extract any other compressed file. You right-click on the file and proceed to extract it.

![Extract 7z File using Nautilus file manager.](https://itsfoss.com/content/images/2023/10/Extract-7z-using-GUI.png)

## Compress a file in 7zip archive format in Linux

You can also use the command line, if it suits you, for this purpose:

`7z a OutputFile files_to_compress`


By default, the archived file will have .7z extension. You can [compress the file in zip format](https://itsfoss.com/linux-zip-folder/) by specifying the extension (.zip) of the output file.

You can compress a file in 7zip archive format graphically. Right-click on the file/directory, and select **Compress**. You should see several types of archive format options. Choose .7z for 7zip.

![Create 7zip Archive Ubuntu using GUI.](https://itsfoss.com/content/images/2023/10/create-7z-archive-GUI.png)

## Conclusion

That’s it. See how easy it is to use 7zip in Linux. I hope you liked this quick tip.

Similarly, you can [use RAR files in Linux](https://itsfoss.com/use-rar-ubuntu-linux/).

[How to Use RAR files in Ubuntu Linux [Quick Tip]Looking for WinRAR in Linux? Here’s how to extract and use RAR files in Linux. RAR is a quite good archive file format. But, it isn’t the best when you’ve got 7-zip in Linux offering great compression ratios and Zip files being easily supported across multiple platforms](https://itsfoss.com/use-rar-ubuntu-linux/)![](https://itsfoss.com/content/images/wordpress/2018/09/rar-ubuntu-linux.png)


![](https://itsfoss.com/content/images/wordpress/2018/09/rar-ubuntu-linux.png)

If you have questions or suggestions, feel free to let me know in the comment sections.