实例 : 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.

目录
相关文章
|
23天前
|
Linux
Linux下使用ls查看文件颜色全部为白色的解决方法,以及Linux中文件颜色介绍
Linux下使用ls查看文件颜色全部为白色的解决方法,以及Linux中文件颜色介绍
70 2
|
24天前
|
Linux
Linux 服务器下载百度网盘文件
本教程指导如何使用 `bypy` 库从百度网盘下载文件。首先通过 `pip install bypy` 安装库,接着运行 `bypy info` 获取登录链接并完成授权,最后将文件置于指定目录并通过 `bypy downdir /Ziya-13b-v1` 命令下载至本地。
30 1
Linux 服务器下载百度网盘文件
|
17天前
|
Ubuntu Linux Shell
Linux系统命令 安装和文件相关命令
本文档详细介绍了Linux系统中的常用命令,包括软件安装卸载命令如`dpkg`和`apt-get`,压缩与解压命令如`gzip`、`bzip2`和`xz`,以及`tar`命令用于打包和解包。此外还介绍了文件分割命令`split`,文件操作命令如`cat`、`head`、`tail`、`more`、`less`等,管道命令和`wc`、`grep`、`find`、`cut`、`sort`、`uniq`、`diff`等实用工具。最后,文档还讲解了文件属性相关的命令如`chmod`、`chown`、`chgrp`以及创建硬链接和软链接的`ln`命令。
|
25天前
|
Linux PHP
Linux CentOS 宝塔 Suhosin禁用php5.6版本eval函数详细图文教程
【8月更文挑战第27天】本文介绍两种禁用PHP执行的方法:使用`PHP_diseval_extension`禁用和通过`suhosin`禁用。由于`suhosin`不支持PHP8,仅适用于PHP7及以下版本,若服务器安装了PHP5.6,则需对应安装`suhosin-0.9.38`版本。文章提供了详细的安装步骤,并强调了宝塔环境下与普通环境下的PHP路径差异。安装完成后,在`php.ini`中添加`suhosin.so`扩展并设置`executor.disable_eval = on`以禁用执行功能。最后通过测试代码验证是否成功禁用,并重启`php-fpm`服务生效。
18 2
|
19天前
|
Linux
centos linux内核下载
centos linux内核下载
|
23天前
|
JavaScript Linux
Linux中和文件相关的操作
Linux中和文件相关的操作
26 0
|
25天前
|
Linux
Linux0.11 文件打开open函数(五)
Linux0.11 文件打开open函数(五)
33 0
|
12月前
|
分布式计算 资源调度 Hadoop
|
11月前
|
应用服务中间件 Linux nginx
【Linux环境】centOS 7安装nginx详细步骤及nginx配置
【Linux环境】centOS 7安装nginx详细步骤及nginx配置
934 0
|
4月前
|
缓存 Linux 编译器
Linux(CentOS7.5) 安装部署 Python3.6(超详细!包含 Yum 源配置!)
该指南介绍了在Linux系统中配置Yum源和安装Python3的步骤。首先,通过`yum install`和`wget`命令更新和备份Yum源,并从阿里云获取CentOS和EPEL的repo文件。接着,清理和更新Yum缓存。然后,下载Python3源代码包,推荐使用阿里云镜像加速。解压后,安装必要的依赖,如gcc。在配置和编译Python3时,可能需要解决缺少C编译器的问题。完成安装后,创建Python3和pip3的软链接,并更新环境变量。最后,验证Python3安装成功,并可选地升级pip和配置pip源以提高包下载速度。