Linux基础知识-压缩、解压缩与归档~19-07.29

1、压缩&解压缩
(zip下载)
mount /dev/sr0 /media/
yum mackcache
yum install zip

1.1、zip&uzip

  • zip 压缩文件名 (test.zip) 要被压缩的文件名
  • zip -m test1.zip test.txt 把test2.txt添加到tset1.zip
  • zip -d test1.zip test2.txt 把test2.txt从test1.zip删除
  • zip test1.zip *.txt -x test10.txt 除test10以外,将所有.txt文件全部压缩到test1.zip
  • zip -r /dir 递归压缩
  • unzip test1.zip
  • unzip test1.zip -d /压缩目录
  • unzip -v test1.zip 不压缩,查看压缩内容

1.2、gzip,gunzip

  • gzip 被压缩的文件 压缩后,源文件不保留
  • gzip -c test.txt >test.txt.gz 压缩,保留原文件
  • gzip -r 目录 压缩目录下的所有内容
  • gunzip test.txt.gz
  • gunzip -c test.txt.gz > /root/test.txt 解压缩到特定的目录下,并且保留源文件
  • gunzip === gzip -d
  • 不解压查看
    [root@localhost test1]# zless test5.txt.gz
    [root@localhost test1]# zless test5.txt.gz

1.3、bzip2,bunzip2

  • bzip2 被压缩的文件名 ,压缩后,源文件不保留
  • bzip2 -c test.txt > test.txt.bz2 压缩,保留源文件
  • bunzip2 test.txt.bz2
  • bunzip2 === bzip2 -d
  • 不解压查看
    [root@localhost test1]# bzcat test5.txt.bz2

1.4、xz,unxz

  • xz 被压缩的文件名 ,压缩后,源文件不保留
    xz dir/*
  • unxz test.txt.xz
  • xz -d test.txt.xz
    xz -d dir/*
  • List itemxzcat test.txt.xz 查看压缩后的文件内容

1.5、tar(用在自己创建的文件)

  • tar -cf etc.tar /etc/
    -c 创建一个归档文件
    -f 指向一个归档文件
    /etc/ 归档文件
  • tar -czf boot.tar.gz /boot/
    -z 以gzip形式将打包的文件压缩
  • tar -cjf boot.tar.bz2 /tmp/
    -j bzip2的形式将打包的文件压缩
  • tar -tf etc.tar
    -t 查看归档文件内容
  • tar --delete etc/hosts -f etc.tar
    –delete 删除etc.tar下的 etc/hosts
  • tar -f etc.tar -r /root/anaconda-ks.cfg.bak
    -r 向打包文件追加新内容 -r 要新加的内容
  • tar tvf etc.tar |grep hosts
    -v 查看详细内容
  • tar xzf boot.tar.gz
    -x 解压
    -xz 解压gzip压缩到归档文件
  • tar xjf boot.tar.bz
    -xf 解压bzip2压缩的归档文件
  • tar xjf tmp.tar.bz2 -C test/
    -C 指定解压路径
  • tar -czvf test.tar.gz file* --remove-files
    –remove-file 打包压缩的同时删除原文件
  • tar xzvf test.tar.gz && rm -rf test.txt.gz
    && 两步,前一步解压文件,后一步把源文件删除

1.6、cpio
(cpio用于系统文件归档与压缩)

  • -t 看归档内容
  • -F 指定归档文件
  • -o: copy-out模式
  • -A 向归档的文件中追加新文件
  • -d 自动建立目录
  • find ./ -depth |cpio -ov -F tree1.cpio
    把当前的文件,归档到tree1.cpio,terr.cpio里面本身有
  • find ./ -depth |cpio -ov -F /tmp/tree1.cpio
    把当前文件归档到/tmp/目录下
  • find ./ -depth -print0 |cpio -null -ov -F /tmp/tree.cpio
    –null 解析空字符
  • cpio -t -F tree.cpio 或者cpio -t < tree.cpio
    查看tree.cpio下的归档内容
  • cpio -t -F /tmp/home.cpio /root/*
    查看home.cpio归档文件里的 /root/下的内容(没有隐藏文件)
  • cpio -t -F /tmp/home.cpio /root/.*
    查看home.cpio归档文件里的 /root/下的内容(全隐藏文件)
  • cpio -t -F /tmp/home.cpio /root/{.,}
    查看home.cpio归档文件里的 /root/下的内容(所有文件)
  • ls /root/test.txt |cpio -oA -F /tmp/home.cpio
    向归档文件中追加文件
  • find /boot-depth -print0 |cpio -oA -F /tmp/home.cpio
    添加新目录
  • cpio -idv -F /tmp/home.cpio
    提取文件
  • find~ -depth -print0 |cpio --null -pvd /tmp/abc
    复制~下文件到/tmp/abc/root/
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值