实例 : Linux系统 centos8 文件打包、解包、压缩、解压缩

简介: Linux 系统环境文件打包、解包、压缩、解压缩
1. gz文件类型:

解压:

[arthur@localhost Documents]$ gzip --help
Usage: gzip [OPTION]... [FILE]...
Compress or uncompress FILEs (by default, compress FILES in-place).
  -d, --decompress  decompress
...
  -1, --fast        compress faster
  -9, --best        compress better

[arthur@localhost Documents]$ ll
total 484
drwxrwxr-x. 2 arthur arthur   4096 Sep  3 08:50 blog
drwxrwxr-x. 2 arthur arthur     42 Apr  7 04:11 log
drwxr-xr-x. 2 arthur arthur     20 Apr 18 23:12 notes
-rwxrwxr-x. 1 arthur arthur 487578 Sep  3 09:30 sample.reads_for.fastq.gz
drwxrwxr-x. 2 arthur arthur     41 Apr 15 09:41 script
[arthur@localhost Documents]$ gzip -d sample.reads_for.fastq.gz 
[arthur@localhost Documents]$ ll
total 1988
drwxrwxr-x. 2 arthur arthur    4096 Sep  3 08:50 blog
drwxrwxr-x. 2 arthur arthur      42 Apr  7 04:11 log
drwxr-xr-x. 2 arthur arthur      20 Apr 18 23:12 notes
-rwxrwxr-x. 1 arthur arthur 1861842 Sep  3 09:30 sample.reads_for.fastq
drwxrwxr-x. 2 arthur arthur      41 Apr 15 09:41 script
2. bz2文件类型
[arthur@localhost Documents]$ bzip2 --help
bzip2, a block-sorting file compressor.  Version 1.0.6, 6-Sept-2010.

   usage: bzip2 [flags and input files in any order]

   -h --help           print this message
   -d --decompress     force decompression
 ...
   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.

[arthur@localhost Documents]$ ll
total 1824
drwxrwxr-x. 2 arthur arthur    4096 Sep  3 08:50 blog
drwxrwxr-x. 2 arthur arthur      42 Apr  7 04:11 log
drwxr-xr-x. 2 arthur arthur      20 Apr 18 23:12 notes
-rwxrwxr-x. 1 arthur arthur 1861842 Sep  3 09:30 sample.reads_for.fastq
drwxrwxr-x. 2 arthur arthur      41 Apr 15 09:41 script
#压缩
[arthur@localhost Documents]$ bzip2 sample.reads_for.fastq 
[arthur@localhost Documents]$ ll
total 320
drwxrwxr-x. 2 arthur arthur   4096 Sep  3 08:50 blog
drwxrwxr-x. 2 arthur arthur     42 Apr  7 04:11 log
drwxr-xr-x. 2 arthur arthur     20 Apr 18 23:12 notes
-rwxrwxr-x. 1 arthur arthur 322712 Sep  3 09:30 sample.reads_for.fastq.bz2
drwxrwxr-x. 2 arthur arthur     41 Apr 15 09:41 script
#解压
[arthur@localhost Documents]$ bunzip2 sample.reads_for.fastq.bz2 
[arthur@localhost Documents]$ ll
total 1824
drwxrwxr-x. 2 arthur arthur    4096 Sep  3 08:50 blog
drwxrwxr-x. 2 arthur arthur      42 Apr  7 04:11 log
drwxr-xr-x. 2 arthur arthur      20 Apr 18 23:12 notes
-rwxrwxr-x. 1 arthur arthur 1861842 Sep  3 09:30 sample.reads_for.fastq
drwxrwxr-x. 2 arthur arthur      41 Apr 15 09:41 script
#压缩: (添加 管道 命令)
[arthur@localhost Documents]$ bzip2 sample.reads_for.fastq  | ll
total 1824
drwxrwxr-x. 2 arthur arthur    4096 Sep  3 08:50 blog
drwxrwxr-x. 2 arthur arthur      42 Apr  7 04:11 log
drwxr-xr-x. 2 arthur arthur      20 Apr 18 23:12 notes
-rwxrwxr-x. 1 arthur arthur 1861842 Sep  3 09:30 sample.reads_for.fastq
-rw-------. 1 arthur arthur       0 Sep  3 09:38 sample.reads_for.fastq.bz2
drwxrwxr-x. 2 arthur arthur      41 Apr 15 09:41 script
[arthur@localhost Documents]$ ll
total 320
drwxrwxr-x. 2 arthur arthur   4096 Sep  3 08:50 blog
drwxrwxr-x. 2 arthur arthur     42 Apr  7 04:11 log
drwxr-xr-x. 2 arthur arthur     20 Apr 18 23:12 notes
-rwxrwxr-x. 1 arthur arthur 322712 Sep  3 09:30 sample.reads_for.fastq.bz2
drwxrwxr-x. 2 arthur arthur     41 Apr 15 09:41 script
#解压:(添加 管道  命令)
[arthur@localhost Documents]$ bzip2 -d sample.reads_for.fastq.bz2  | ll
total 320
drwxrwxr-x. 2 arthur arthur   4096 Sep  3 08:50 blog
drwxrwxr-x. 2 arthur arthur     42 Apr  7 04:11 log
drwxr-xr-x. 2 arthur arthur     20 Apr 18 23:12 notes
-rw-------. 1 arthur arthur      0 Sep  3 09:39 sample.reads_for.fastq
-rwxrwxr-x. 1 arthur arthur 322712 Sep  3 09:30 sample.reads_for.fastq.bz2
drwxrwxr-x. 2 arthur arthur     41 Apr 15 09:41 script
[arthur@localhost Documents]$ ll
total 1824
drwxrwxr-x. 2 arthur arthur    4096 Sep  3 08:50 blog
drwxrwxr-x. 2 arthur arthur      42 Apr  7 04:11 log
drwxr-xr-x. 2 arthur arthur      20 Apr 18 23:12 notes
-rwxrwxr-x. 1 arthur arthur 1861842 Sep  3 09:30 sample.reads_for.fastq
drwxrwxr-x. 2 arthur arthur      41 Apr 15 09:41 script
3. xz文件类型:
[arthur@localhost Documents]$ xz --help 
Usage: xz [OPTION]... [FILE]...
Compress or decompress FILEs in the .xz format.

  -z, --compress      force compression
  -d, --decompress    force decompression
  -t, --test          test compressed file integrity
  -l, --list          list information about .xz files
4. tar.gztar.bz2文件类型:
[arthur@localhost Documents]$ tar --help 
Usage: tar [OPTION...] [FILE]...
GNU 'tar' saves many files together into a single tape or disk archive, and can
restore individual files from the archive.

Examples:
  tar -cf archive.tar foo bar  # Create archive.tar from files foo and bar.
  tar -tvf archive.tar         # List all files in archive.tar verbosely.
  tar -xf archive.tar          # Extract all files from archive.tar.

########################################################################
文件打包与解包
#查看当前目录与文件 
[arthur@localhost Documents]$ ll
total 5472
drwxrwxr-x. 2 arthur arthur    4096 Sep  3 08:50 blog
drwxrwxr-x. 2 arthur arthur      42 Apr  7 04:11 log
drwxr-xr-x. 2 arthur arthur      20 Apr 18 23:12 notes
-rwxrwxr-x. 1 arthur arthur 1861842 Sep  3 09:53 sample.reads_for.fastq
-rwxrwxr-x. 1 arthur arthur 1861842 Sep  3 09:30 sample.reads_rev.fastq
drwxrwxr-x. 2 arthur arthur      41 Apr 15 09:41 script
#将文件 for 和 rev 打包为 seq.tar
[arthur@localhost Documents]$ tar -cf seq.tar sample.reads_for.fastq  sample.reads_rev.fastq && ll
total 9112
drwxrwxr-x. 2 arthur arthur    4096 Sep  3 08:50 blog
drwxrwxr-x. 2 arthur arthur      42 Apr  7 04:11 log
drwxr-xr-x. 2 arthur arthur      20 Apr 18 23:12 notes
-rwxrwxr-x. 1 arthur arthur 1861842 Sep  3 09:53 sample.reads_for.fastq
-rwxrwxr-x. 1 arthur arthur 1861842 Sep  3 09:30 sample.reads_rev.fastq
drwxrwxr-x. 2 arthur arthur      41 Apr 15 09:41 script
-rw-rw-r--. 1 arthur arthur 3727360 Sep  3 09:54 seq.tar
#查看包内文件:
[arthur@localhost Documents]$ tar -tvf seq.tar 
-rwxrwxr-x arthur/arthur 1861842 2021-09-03 09:53 sample.reads_for.fastq
-rwxrwxr-x arthur/arthur 1861842 2021-09-03 09:30 sample.reads_rev.fastq
#解开包并将包内文件输出到新的路径下
[arthur@localhost Documents]$ tar -xf seq.tar  -C ../Desktop/
[arthur@localhost Documents]$ ll ../Desktop/ 
total 5420
-rw-rw-r--. 1 arthur arthur  162525 Apr 14 11:37 20210414log
-rw-rw-r--. 1 arthur arthur 1441063 Apr 15 02:44 20210415.log
-rw-rw-r--. 1 arthur arthur   46384 Apr 18 10:25 20210418log
-rwxrwxr-x. 1 arthur arthur 1861842 Sep  3 09:53 sample.reads_for.fastq
-rwxrwxr-x. 1 arthur arthur 1861842 Sep  3 09:30 sample.reads_rev.fastq
[arthur@localhost Documents]$ ll
total 7284
drwxrwxr-x. 2 arthur arthur    4096 Sep  3 08:50 blog
drwxrwxr-x. 2 arthur arthur      42 Apr  7 04:11 log
drwxr-xr-x. 2 arthur arthur      20 Apr 18 23:12 notes
-rwxrwxr-x. 1 arthur arthur 1861842 Sep  3 09:53 sample.reads_for.fastq
-rwxrwxr-x. 1 arthur arthur 1861842 Sep  3 09:30 sample.reads_rev.fastq
drwxrwxr-x. 2 arthur arthur      41 Apr 15 09:41 script
-rw-rw-r--. 1 arthur arthur 3727360 Sep  3 09:54 seq.tar
########################################################################
文件打包压缩与文件解包解压缩
tar 可以使用 -z 参数来调用gzip进行压缩;使用 -j 参数来调用 bzip2 进行压缩;
tar 调用 compress , compress 也是一个压缩程序, `.Z`结尾的文件就是 bzip2 压缩的结果。相对应解压程序为 uncompress. tar 中使用 -Z  参数调用 compress 

#文件打包压缩为 seq.tar.gz,  参数 `-Z`
#此处输出文件命名不规范,应为  seq.tar.Z
[arthur@localhost Documents]$ tar -Zcf seq.tar.gz sample.reads_for.fastq  sample.reads_rev.fastq 
[arthur@localhost Documents]$ ll
total 8108
drwxrwxr-x. 2 arthur arthur    4096 Sep  3 08:50 blog
drwxrwxr-x. 2 arthur arthur      42 Apr  7 04:11 log
drwxr-xr-x. 2 arthur arthur      20 Apr 18 23:12 notes
-rwxrwxr-x. 1 arthur arthur 1861842 Sep  3 09:53 sample.reads_for.fastq
-rwxrwxr-x. 1 arthur arthur 1861842 Sep  3 09:30 sample.reads_rev.fastq
drwxrwxr-x. 2 arthur arthur      41 Apr 15 09:41 script
-rw-rw-r--. 1 arthur arthur 3727360 Sep  3 09:54 seq.tar
-rw-rw-r--. 1 arthur arthur  841611 Sep  3 10:16 seq.tar.gz
#文件打包压缩为 seq2.tar.gz,  参数 `z`
[arthur@localhost Documents]$ tar -zcf seq2.tar.gz sample.reads_for.fastq  sample.reads_rev.fastq 
[arthur@localhost Documents]$ ll
total 9060
drwxrwxr-x. 2 arthur arthur    4096 Sep  3 08:50 blog
drwxrwxr-x. 2 arthur arthur      42 Apr  7 04:11 log
drwxr-xr-x. 2 arthur arthur      20 Apr 18 23:12 notes
-rwxrwxr-x. 1 arthur arthur 1861842 Sep  3 09:53 sample.reads_for.fastq
-rwxrwxr-x. 1 arthur arthur 1861842 Sep  3 09:30 sample.reads_rev.fastq
drwxrwxr-x. 2 arthur arthur      41 Apr 15 09:41 script
-rw-rw-r--. 1 arthur arthur  974587 Sep  3 10:19 seq2.tar.gz
-rw-rw-r--. 1 arthur arthur 3727360 Sep  3 09:54 seq.tar
-rw-rw-r--. 1 arthur arthur  841611 Sep  3 10:16 seq.tar.gz
#创建目录存放解包解压缩文件
[arthur@localhost Documents]$ mkdir seq2 seq1
[arthur@localhost Documents]$ ll
total 9060
drwxrwxr-x. 2 arthur arthur    4096 Sep  3 08:50 blog
drwxrwxr-x. 2 arthur arthur      42 Apr  7 04:11 log
drwxr-xr-x. 2 arthur arthur      20 Apr 18 23:12 notes
-rwxrwxr-x. 1 arthur arthur 1861842 Sep  3 09:53 sample.reads_for.fastq
-rwxrwxr-x. 1 arthur arthur 1861842 Sep  3 09:30 sample.reads_rev.fastq
drwxrwxr-x. 2 arthur arthur      41 Apr 15 09:41 script
drwxrwxr-x. 2 arthur arthur       6 Sep  3 10:21 seq1
drwxrwxr-x. 2 arthur arthur       6 Sep  3 10:21 seq2
-rw-rw-r--. 1 arthur arthur  974587 Sep  3 10:19 seq2.tar.gz
-rw-rw-r--. 1 arthur arthur 3727360 Sep  3 09:54 seq.tar
-rw-rw-r--. 1 arthur arthur  841611 Sep  3 10:16 seq.tar.gz
#
[arthur@localhost seq2]$ tar -zxvf ../seq2.tar.gz 
sample.reads_for.fastq
sample.reads_rev.fastq
[arthur@localhost seq2]$ cd ../
[arthur@localhost Documents]$ cd seq1
#
[arthur@localhost seq1]$ tar -Zxvf ../seq.tar.gz  
sample.reads_for.fastq
sample.reads_rev.fastq
5. 解压缩文件总结:
  1. 对于.tar结尾的文件:

    • tar -xf file.tar
  2. 对于.gz结尾的文件:
    -gzip -d file.gz
    -gunzip file.gz
  3. 对于.tgz.tar.gz结尾的文件
    -tar -zxvf file.tar.gz
    -tar -zxvf file.tgz
  4. 对于.bz2结尾的文件:
    -bzip2 -d file.bz2
    -bunzip2 file.bz2
  5. 对于tar.bz2结尾的文件:
    -tar -jxvf file.tar.bz2
  6. 对于.Z结尾的文件:
    -uncompress file.Z
  7. 对于.tar.Z结尾的文件:
    -tar -xZf file.tar.Z

reference :
[1] 鸟哥私房菜
[2] 解压缩、压缩命令.runoob.

目录
相关文章
|
3月前
|
Linux 网络安全 Python
linux centos上安装python3.11.x详细完整教程
这篇文章提供了在CentOS系统上安装Python 3.11.x版本的详细步骤,包括下载、解压、安装依赖、编译配置、解决常见错误以及版本验证。
1697 1
linux centos上安装python3.11.x详细完整教程
|
7天前
|
负载均衡 Ubuntu 应用服务中间件
nginx修改网站默认根目录及发布(linux、centos、ubuntu)openEuler软件源repo站点
通过合理配置 Nginx,我们可以高效地管理和发布软件源,为用户提供稳定可靠的服务。
41 13
|
4月前
|
安全 关系型数据库 MySQL
Linux(CentOS6)安装MySQL5.6
Linux(CentOS 6)系统上安装MySQL 5.6版本的详细步骤,包括准备数据存放目录、创建用户、下载安装包、初始化数据库、配置服务脚本、设置环境变量等操作。
439 1
|
4月前
|
Linux
在Linux中,列出几种常见打包工具并写相应解压缩参数。
在Linux中,列出几种常见打包工具并写相应解压缩参数。
|
2月前
|
Web App开发 搜索推荐 Unix
Linux系统之MobaXterm远程连接centos的GNOME桌面环境
【10月更文挑战第21天】Linux系统之MobaXterm远程连接centos的GNOME桌面环境
473 4
Linux系统之MobaXterm远程连接centos的GNOME桌面环境
|
2月前
|
Linux 网络安全 数据安全/隐私保护
Linux系统之Centos7安装cockpit图形管理界面
【10月更文挑战第12天】Linux系统之Centos7安装cockpit图形管理界面
112 1
Linux系统之Centos7安装cockpit图形管理界面
|
2月前
|
Web App开发 网络协议 Linux
linux命令总结(centos):shell常用命令汇总,平时用不到,用到就懵逼忘了,于是专门写了这篇论文,【便持续更新】
这篇文章是关于Linux命令的总结,涵盖了从基础操作到网络配置等多个方面的命令及其使用方法。
80 1
linux命令总结(centos):shell常用命令汇总,平时用不到,用到就懵逼忘了,于是专门写了这篇论文,【便持续更新】
|
2月前
|
Linux Docker 容器
Centos安装docker(linux安装docker)——超详细小白可操作手把手教程,包好用!!!
本篇博客重在讲解Centos安装docker,经博主多次在不同服务器上测试,极其的稳定,尤其是阿里的服务器,一路复制命令畅通无阻。
2200 4
Centos安装docker(linux安装docker)——超详细小白可操作手把手教程,包好用!!!
|
2月前
|
存储 网络协议 Linux
AWS实操-EC2-创建购买linux(centos)EC2服务器
AWS实操-EC2-创建购买linux(centos)EC2服务器
|
3月前
|
NoSQL Linux Redis
linux之centos安装redis
linux之centos安装redis

热门文章

最新文章