Linux(11)、压缩、解压命令

压缩

  • 压缩格式: gz、bz2、xz、zip、z
  • 压缩算法不同,压缩比可能也不同
  • 古老的压缩和解压方式:compress、uncompress,压缩比较小

gzip

  • 只能压缩文件
  • 命令:gzip /path/to/somefilefile
  • 自动生成file_name.gz,且删除源文件,压缩比>10
    [[email protected] fangqihan]# ls
    1.txt
    [[email protected] fangqihan]# gzip 1.txt
    [[email protected] fangqihan]# ls
    1.txt.gz 
  • 解压:
    [[email protected] fangqihan]# ls
    1.txt.gz
    [[email protected] fangqihan]# gunzip 1.txt.gz
    [[email protected] fangqihan]# ls
    1.txt
  • 不解压查看数据:
    [[email protected] fangqihan]# ls
    1.txt.gz
    [[email protected] fangqihan]# zcat 1.txt.gz
    haha
    hello linux
    -bash: asas: 未找到命令
    wewe

bzip2

  • 后缀.bz2
  • 只能压缩文件
  • 比gzip有着更大的压缩比
  • 使用格式近似。
  • 默认压缩后也会删除源文件。
  • 可以指定-k: 压缩后保留源文件
  • 解压:bunzip2 file_path
  • 不解压查看压缩后的文件内容:bzcat

xz

  • 后缀.xz
  • 先安装:yum install xz
  • 可以指定-k: 压缩后保留源文件
  • 解压:unxz file_path
  • 不解压查看文件:xzcat

归档

zip

  • 归档:archive,归档本身并不意味着压缩。
  • 安装:yum install zip
  • 可以将多个文件压缩成一个文件。
  • 格式:zip FILE.zip file1,file2, ...
[[email protected] fangqihan]# zip total.zip 1.txt a.txt c.txt
  adding: 1.txt (stored 0%)
  adding: a.txt (deflated 42%)
  adding: c.txt (deflated 31%)
[[email protected] fangqihan]# ls
1.txt  a.txt  b.txt  c.txt  total.zip
  • 解压:unzip
yum install unzip  # 先安装unzip

[[email protected] fangqihan]# ls
c.txt  total.zip
[[email protected] fangqihan]# unzip total.zip
Archive:  total.zip
 extracting: 1.txt
  inflating: a.txt
replace c.txt? [y]es, [n]o, [A]ll, [N]one, [r]ename: A
  inflating: c.txt
[[email protected] fangqihan]# ls
1.txt  a.txt  c.txt  total.zip

tar

  • 归档工具,只归档不压缩,体积会增大;
  • -c:创建归档文件
  • -f FILE.tar:操作的归档文件
  • tar -cf test.rar pattren
    # 将所有以test开头的文件归档起来
    [[email protected] fangqihan]# ls
    1.txt  a.txt  c.txt
    [[email protected] fangqihan]# tar -cf test.rar *.txt
    [[email protected] fangqihan]# ls
    1.txt  a.txt  c.txt  test.rar
  • 还原归档:tar -xf file.tar,解压归档后的文件
    [[email protected] fangqihan]# ls
    test.rar
    [[email protected] fangqihan]# tar -xf test.rar
    [[email protected] fangqihan]# ls
    1.txt  a.txt  c.txt  test.rar
  • -xattrs归档时,保留文件的扩展属性信息
  • -t: 不展开归档,直接查看归档了哪些文件 tar -tf file.tar
    [[email protected] fangqihan]# tar -tf test.rar
    1.txt
    a.txt
    c.txt
  • 归档后可以再进行压缩:xz file.tar
    [[email protected] fangqihan]# xz test.rar
    [[email protected] fangqihan]# ls
    test.rar.xz

原文地址:https://www.cnblogs.com/fqh202/p/9438691.html

时间: 2024-08-28 21:06:45

Linux(11)、压缩、解压命令的相关文章

Linux学习 - 压缩解压命令

一." .gz "压缩文件 1 压缩语法 gzip  [文件] 2 解压语法 gunzip  [压缩文件] 3 注 gzip只能压缩文件 gzip不保留原文件 二." .bz2 "压缩文件 1 压缩语法 bzip2  [-k]  [文件] -k 产生压缩文件后保留原文件(keep) 2 解压语法 bunzip2  [-k]  [文件] -k 产生解压文件后保留原压缩文件(keep) 3 说明 bzip2只能压缩文件 三." .tar.gz "压缩

linux tar 压缩解压命令

tar命令: -c 压缩-x 解压缩-t 不解压的情况下查看文件内容-r 向压缩文件追加文件-u 更新压缩文件 以上参数必须和'-f'参数连用,且'-f'必须为最后一个参数,后接文档名 -z 对应gzip-j 对应bz2 原文出自:http://www.cnblogs.com/jyaray/archive/2011/04/30/2033362.html

linux tar压缩解压命令的详细解释

tar [-cxtzjvfpPN] 文件与目录 参数:-c :建立一个压缩文件的参数指令(create 的意思):-x :解开一个压缩文件的参数指令!-t :查看 tarfile 里面的文件!特别注意,在参数的下达中, c/x/t 仅能存在一个!不可同时存在!因为不可能同时压缩与解压缩.-z :是否同时具有 gzip 的属性?亦即是否需要用 gzip 压缩?-j :是否同时具有 bzip2 的属性?亦即是否需要用 bzip2 压缩?-v :压缩的过程中显示文件!这个常用,但不建议用在背景执行过程

linux命令之——压缩解压命令

linux命令之——压缩解压命令 命令名称:gzip 命令英文原意:GUN zip 命令所在路径:/bin/gzip 执行权限:所有用户 语法:gzip[文件] 功能描述:压缩文件(且只能压缩文件,不保存原文件) 压缩文件格式:.gz 范例: 压缩  :gzip boduo                      压缩后的文件格式为 boduo.gz 解压缩:gunzip boduo.gz            或者(gzip -d boduo.gz) ====================

Linux压缩解压命令详细介绍(gizp、tag、zip、bzip2)

--------------------------------------压缩解压命令------------------------------- *windos可以解压所有linux系统的文件压缩包,但linux不一定能够全部解压windos的 一: gzip :压缩文件 ---  GUN zip    .gz文件格式 特点:1只能压缩文件,不能压缩目录 2不保留源文件 例子:gzip newfile   就会产生一个newfile.gz的一个文件包 gunzip :解压缩(或者用gzip

linux笔记:linux常用命令-压缩解压命令

压缩解压命令:gzip(压缩文件,不保留原文件.这个命令不能压缩目录) 压缩解压命令:gunzip(解压.gz的压缩文件) 压缩解压命令:tar(打包压缩目录或者解压压缩文件.打包的意思是把目录打包成一个文件,不等同于压缩.tar命令可以在打包的同时进行压缩,得到.tar.gz文件) 压缩解压命令:zip(压缩文件或者目录,会保留原文件) 压缩解压命令:unzip(解压.zip的压缩文件) 压缩解压命令:bzip2(压缩文件) 压缩解压命令:bunzip2(解压.bz2的文件)

Linux下解包/打包,压缩/解压命令

.tar 解包:tar xvf FileName.tar 打包:tar cvf fileName.tar DirName tar.gz和.tgz 解压:tar zxvf FileName.tar.zip [-C DirName] 压缩:tar zcvf FileName.tar.zip DirName .tar.bz2 解压:tar jxvf FileName.tar.bz2 或tar -bzip xvf FileName.tar.bz2 压缩:tar jcvf FileName.tar.bz2

压缩&&解压命令汇总

以下是搜集的Linux系统下,压缩&&解压命令,以备参考使用. .tar 解包: tar xvf FileName.tar 打包:tar cvf FileName.tar DirName    tar cvf a.tar a.txt b.txt c.txt (注:tar是打包,不是压缩!) --------------------------------------------- .gz 解压1:gunzip FileName.gz 解压2:gzip -d FileName.gz 压缩:g

Ubuntu 压缩解压命令

压缩解压命令 在讲 Linux 上的压缩工具之前,有必要先了解一下常见常用的压缩包文件格式.在 Windows 上最常见的不外乎这三种*.zip,*.rar,*.7z 后缀的压缩文件,而在 Linux 上面常见常用的除了以上三种外,还有 *.gz,*.xz,*.bz2,*.tar,*.tar.gz,*.tar.xz,*.tar.bz2,简单介绍如下 |文件后缀名| 说明|例子 | | --- | ---| --- | |.zip| zip 程序打包压缩的文件| |.rar |rar 程序压缩的文

压缩解压命令

压缩解压命令 :gzip命令名称:gzip命令英文原意:GNU zip命令所在路径:/bin/gzip执行权限:所有用户语法:gzip [文件]功能描述:压缩文件压缩后文件格式:.gz 压缩解压命令 :gunzip命令名称:gunzip命令英文原意:GNU unzip命令所在路径:/bin/gunzip执行权限:所有用户语法:gunzip [压缩文件]功能描述:解压缩.gz的压缩文件范例: $ gunzip boduo.gz  或 $ gzip -d boduo.gz gzip 只能压缩文件,不