mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-01-13 22:30:37 +08:00
translated
This commit is contained in:
parent
284d22afa6
commit
7a7bb967e3
@ -1,121 +0,0 @@
|
||||
translating--geekpi
|
||||
|
||||
How to Compress and Decompress a .bz2 File in Linux
|
||||
============================================================
|
||||
|
||||
To compress a file(s), is to significantly decrease the size of the file(s) by encoding data in the file(s) using less bits, and it is normally a useful practice [during backup and transfer of a file(s)][1] over a network. On the other hand, decompressing a file(s) means restoring data in the file(s) to its original state.
|
||||
|
||||
There are several [file compression and decompression tools][2] available in Linux such as gzip, 7-zip, Lrzip, [PeaZip][3] and many more.
|
||||
|
||||
In this tutorial, we will look at how to compress and decompress `.bz2` files using the bzip2 tool in Linux.
|
||||
|
||||
Bzip2 is a well known compression tool and it’s available on most if not all the major Linux distributions, you can use the appropriate command for your distribution to install it.
|
||||
|
||||
```
|
||||
$ sudo apt install bzip2 [On Debian/Ubuntu]
|
||||
$ sudo yum install bzip2 [On CentOS/RHEL]
|
||||
$ sudo dnf install bzip2 [On Fedora 22+]
|
||||
```
|
||||
|
||||
The conventional syntax of using bzip2 is:
|
||||
|
||||
```
|
||||
$ bzip2 option(s) filenames
|
||||
```
|
||||
|
||||
### How to Use “bzip2” to Compress Files in Linux
|
||||
|
||||
You can compress a file as below, where the flag `-z` enables file compression:
|
||||
|
||||
```
|
||||
$ bzip2 filename
|
||||
OR
|
||||
$ bzip2 -z filename
|
||||
```
|
||||
|
||||
To compress a `.tar` file, use the command format:
|
||||
|
||||
```
|
||||
$ bzip2 -z backup.tar
|
||||
```
|
||||
|
||||
Important: By default, bzip2 deletes the input files during compression or decompression, to keep the input files, use the `-k` or `--keep` option.
|
||||
|
||||
In addition, the `-f` or `--force` flag will force bzip2 to overwrite an existing output file.
|
||||
|
||||
```
|
||||
------ To keep input file ------
|
||||
$ bzip2 -zk filename
|
||||
$ bzip2 -zk backup.tar
|
||||
```
|
||||
|
||||
You can as well set the block size to 100k upto 900k, using `-1` or `--fast` to `-9` or –best as shown in the below examples:
|
||||
|
||||
```
|
||||
$ bzip2 -k1 Etcher-linux-x64.AppImage
|
||||
$ ls -lh Etcher-linux-x64.AppImage.bz2
|
||||
$ bzip2 -k9 Etcher-linux-x64.AppImage
|
||||
$ bzip2 -kf9 Etcher-linux-x64.AppImage
|
||||
$ ls -lh Etcher-linux-x64.AppImage.bz2
|
||||
```
|
||||
|
||||
The screenshot below shows how to use options to keep the input file, force bzip2 to overwrite an output file and set the block size during compression.
|
||||
|
||||
[
|
||||
![Compress Files Using bzip2 in Linux](http://www.tecmint.com/wp-content/uploads/2016/11/Compress-Files-Using-bzip2-in-Linux.png)
|
||||
][4]
|
||||
|
||||
Compress Files Using bzip2 in Linux
|
||||
|
||||
### How to Use “bzip2” to Decompress Files in Linux
|
||||
|
||||
To decompress a `.bz2` file, make use of the `-d` or `--decompress` option like so:
|
||||
|
||||
```
|
||||
$ bzip2 -d filename.bz2
|
||||
```
|
||||
|
||||
Note: The file must end with a `.bz2` extension for the command above to work.
|
||||
|
||||
```
|
||||
$ bzip2 -vd Etcher-linux-x64.AppImage.bz2
|
||||
$ bzip2 -vfd Etcher-linux-x64.AppImage.bz2
|
||||
$ ls -l Etcher-linux-x64.AppImage
|
||||
```
|
||||
[
|
||||
![Decompress bzip2 File in Linux](http://www.tecmint.com/wp-content/uploads/2016/11/Decompression-bzip2-File-in-Linux.png)
|
||||
][5]
|
||||
|
||||
Decompress bzip2 File in Linux
|
||||
|
||||
To view the bzip2 help page and man page, type the command below:
|
||||
|
||||
```
|
||||
$ bzip2 -h
|
||||
$ man bzip2
|
||||
```
|
||||
|
||||
Lastly, with the simple elaborations above, I believe you are now capable of compressing and decompressing `.bz2` files using the bzip2 tool in Linux. However, for any questions or feedback, reach us using the comment section below.
|
||||
|
||||
Importantly, you may want to go over a few important [Tar command examples][6] in Linux so as to learn using the tar utility to [create compressed archive files][7].
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.tecmint.com/linux-compress-decompress-bz2-files-using-bzip2
|
||||
|
||||
作者:[Aaron Kili][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://www.tecmint.com/author/aaronkili/
|
||||
[1]:http://www.tecmint.com/rsync-local-remote-file-synchronization-commands/
|
||||
[2]:http://www.tecmint.com/command-line-archive-tools-for-linux/
|
||||
[3]:http://www.tecmint.com/peazip-linux-file-manager-and-file-archive-tool/
|
||||
[4]:http://www.tecmint.com/wp-content/uploads/2016/11/Compress-Files-Using-bzip2-in-Linux.png
|
||||
[5]:http://www.tecmint.com/wp-content/uploads/2016/11/Decompression-bzip2-File-in-Linux.png
|
||||
[6]:http://www.tecmint.com/18-tar-command-examples-in-linux/
|
||||
[7]:http://www.tecmint.com/compress-files-and-finding-files-in-linux/
|
||||
|
||||
|
@ -0,0 +1,121 @@
|
||||
如何在Linux中压缩及解压缩.bz2文件
|
||||
============================================================
|
||||
|
||||
压缩文件是使用较少的位对文件中的数据进行编码来显著地减小文件的大小,并且[在文件的备份和传送期间][1]是一个有用的实践。 另一方面,解压文件意味着将文件中的数据恢复到原始状态。
|
||||
|
||||
Linux中几个[文件压缩和解压缩工具][2],比如gzip、7-zip、Lrzip、[PeaZip][3]等等。
|
||||
|
||||
本篇教程中,我们将如何在Linux中使用bzip2工具压缩及解压缩`.bz2`文件。
|
||||
|
||||
bzip2是一个非常有名的压缩工具,并且在大多数主流Linux发行版上都有,你可以在你的发行版上用合适的命令来安装。
|
||||
|
||||
```
|
||||
$ sudo apt install bzip2 [On Debian/Ubuntu]
|
||||
$ sudo yum install bzip2 [On CentOS/RHEL]
|
||||
$ sudo dnf install bzip2 [On Fedora 22+]
|
||||
```
|
||||
|
||||
使用bzip2的常规语法是:
|
||||
|
||||
```
|
||||
$ bzip2 option(s) filenames
|
||||
```
|
||||
|
||||
### 如何在Linux中使用“bzip2”压缩文件
|
||||
|
||||
你可以如下压缩一个文件,使用`-z`标志启用压缩:
|
||||
|
||||
```
|
||||
$ bzip2 filename
|
||||
或者
|
||||
$ bzip2 -z filename
|
||||
```
|
||||
|
||||
要压缩一个`.tar`文件,使用的命令为:
|
||||
|
||||
```
|
||||
$ bzip2 -z backup.tar
|
||||
```
|
||||
|
||||
重要:bzip2默认会在压缩及解压缩文件中删除输入文件,要保留输入文件,使用`-k`或者`--keep`选项。
|
||||
|
||||
额外地,`-f`或者`--force`标志会强制让bzip2覆盖输出文件
|
||||
|
||||
```
|
||||
------ 要保留输入文件 ------
|
||||
$ bzip2 -zk filename
|
||||
$ bzip2 -zk backup.tar
|
||||
```
|
||||
|
||||
你也可以设置块的大小从100k到900k,使用`-1`或者`--fast`到`-9`或者`--best`:
|
||||
|
||||
```
|
||||
$ bzip2 -k1 Etcher-linux-x64.AppImage
|
||||
$ ls -lh Etcher-linux-x64.AppImage.bz2
|
||||
$ bzip2 -k9 Etcher-linux-x64.AppImage
|
||||
$ bzip2 -kf9 Etcher-linux-x64.AppImage
|
||||
$ ls -lh Etcher-linux-x64.AppImage.bz2
|
||||
```
|
||||
|
||||
下面的截屏展示了如何使用选项来保留输入文件,强制bzip2覆盖输出文件,并且在压缩中设置块的大小。
|
||||
|
||||
[
|
||||
![Compress Files Using bzip2 in Linux](http://www.tecmint.com/wp-content/uploads/2016/11/Compress-Files-Using-bzip2-in-Linux.png)
|
||||
][4]
|
||||
|
||||
在Linux中使用bzip2压缩文件
|
||||
|
||||
### 如何在Linux中使用“bzip2”解压缩文件
|
||||
|
||||
要解压缩`.bz2`文件,确保使用`-d`或者`--decompress`选项:
|
||||
|
||||
```
|
||||
$ bzip2 -d filename.bz2
|
||||
```
|
||||
|
||||
注意:这个文件必须是`.bz2`的扩展名,上面的命令才能使用。
|
||||
|
||||
```
|
||||
$ bzip2 -vd Etcher-linux-x64.AppImage.bz2
|
||||
$ bzip2 -vfd Etcher-linux-x64.AppImage.bz2
|
||||
$ ls -l Etcher-linux-x64.AppImage
|
||||
```
|
||||
[
|
||||
![Decompress bzip2 File in Linux](http://www.tecmint.com/wp-content/uploads/2016/11/Decompression-bzip2-File-in-Linux.png)
|
||||
][5]
|
||||
|
||||
Decompress bzip2 File in Linux
|
||||
在Linux中解压bzip2文件
|
||||
|
||||
要浏览bzip2的帮助及man页面,输入下面的命令:
|
||||
|
||||
```
|
||||
$ bzip2 -h
|
||||
$ man bzip2
|
||||
```
|
||||
|
||||
最后,通过上面简单的阐述,我相信你现在已经可以在Linux中压缩及解压缩`bz2`文件了。然而,有任何的问题和反馈,可以在评论区中留言。
|
||||
|
||||
重要的是,你可能想在Linux中查看一些重要的[tar命令示例][6],以便学习使用tar命令来[创建压缩归档文件][7]。
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://www.tecmint.com/linux-compress-decompress-bz2-files-using-bzip2
|
||||
|
||||
作者:[Aaron Kili][a]
|
||||
译者:[geekpi](https://github.com/geekpi)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://www.tecmint.com/author/aaronkili/
|
||||
[1]:http://www.tecmint.com/rsync-local-remote-file-synchronization-commands/
|
||||
[2]:http://www.tecmint.com/command-line-archive-tools-for-linux/
|
||||
[3]:http://www.tecmint.com/peazip-linux-file-manager-and-file-archive-tool/
|
||||
[4]:http://www.tecmint.com/wp-content/uploads/2016/11/Compress-Files-Using-bzip2-in-Linux.png
|
||||
[5]:http://www.tecmint.com/wp-content/uploads/2016/11/Decompression-bzip2-File-in-Linux.png
|
||||
[6]:http://www.tecmint.com/18-tar-command-examples-in-linux/
|
||||
[7]:http://www.tecmint.com/compress-files-and-finding-files-in-linux/
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user