• Linux | 备份压缩命令


    1、tar命令:打包和备份

    【语法格式】

    tar [参数] [文件或目录]
    

    【常用参数】

    • -c:创建压缩文件
    • -x:解开压缩文件
    • -t:查看压缩包内有哪些文件
    • -v:显示压缩或解压的过程
    • -f:目标文件名
    • -p:保留原始的权限与属性
    • -P:使用绝对路径来压缩
    • -C:指定解压到的目录
    • -z:用Gzip压缩或解压
    • -j:用bzip2压缩或解压
    • --remove-files:打包/压缩之后删除源文件

    【实例】

    将所有.txt文件打包成为一个名为file.tar的包

    [root@localhost ~]# touch a{1..20}.txt
    [root@localhost ~]# tar -cf a.tar *.txt
    

    打包文件之后删除源文件

    [root@localhost ~]# tar -cvf a.tar *.txt --remove-file
    

    解包

    [root@localhost ~]# tar -xf a.tar
    

    将打包文件以gzip格式压缩

    [root@localhost ~]# tar -zcvf a.tar.gz a.tar
    

    将打包文件以bzip2格式压缩

    [root@localhost ~]# tar -jcvf a.tar.zip a.tar
    

    解压gzip格式压缩包

    [root@localhost ~]# tar -zxvf a.tar.gz
    

    解压bzip2格式的压缩包

    [root@localhost ~]# tar -jxvf a.tar.zip
    

    将压缩包解压到指定目录

    [root@localhost ~]# tar -zxvf a.tar.gz -C dir
    

    2、gzip命令:压缩和解压文件

    【语法格式】

    gzip [参数]
    

    【常用参数】

    • -a:使用ASCII文字模式
    • -d:解开压缩文件
    • -f:强行压缩文件
    • -l:列出压缩文件的相关信息
    • -c:把压缩后的文件输出到标准输出设备,不去更动原始文件
    • -r:递归处理,将指定目录下的所有文件及子目录一并处理
    • -q:不显示警告信息

    【实例】

    将dir目录下的每个文件压缩成.gz文件

    [root@localhost ~]# gzip dir/*
    

    将dir目录下的每个压缩文件进行解压,并列出详细的信息

    [root@localhost ~]# gzip -dl dir/*
    
  • 相关阅读:
    Exercise02_09
    Exercise02_05
    Exercise02_01
    Exercise02_03
    Exercise02_07
    web.xml配置详解
    面对不成功的人生
    请不以结婚为目的的恋爱吧
    年轻人能为世界做点什么
    不作就不会活
  • 原文地址:https://www.cnblogs.com/Cyzhouke/p/13742636.html
Copyright © 2020-2023  润新知