tar、cpio

tar:压缩一些用户的普通文件

-c:创建一个新的归档文件

-f:指向一个归档文件

/etc/:被归档的文件

[root@localhost tar]# tar -cf etc.tar /etc/

-z:以gzip的形式将打包的文件压缩

[root@localhost tar]# tar -czf boot.tar.gz /boot/

-j:以bzip2的形式将打包文件压缩

[root@localhost tar]# tar -cjf tmp.tar.bz2 /tmp/

[root@localhost tar]# tar -tf etc.tar

–delete:删除etc.tar下的etc/hosts

[root@localhost tar]# tar --delete etc/hosts -f etc.tar

-r:向打包文件中追加新内容

[root@localhost tar]# tar -f etc.tar -r /root/anaconda-ks.cfg

-v:查看详细信息

[root@localhost tar]# tar -tvf etc.tar |grep hosts

-x:解压

-xz:解压gzip压缩的归档文件

[root@localhost tar]# tar xzf boot.tar.gz

-xj:解压bzip2压缩的归档文件

[root@localhost tar]# tar xjf tmp.tar.bz2

-C:指定解压路径

[root@localhost tar]# tar xjf tmp.tar.bz2 -C test/

–remove-files 打包压缩的同时删除源文件

tar -czvf test.tar.gz file* --remove-files

&& 两步,前一步解压文件,后一步吧源文件删掉

tar xzvf test.tar.gz && rm -rf test.tar.gz

cpio:系统上的文件

find查找文件到一半的时候cpio开始工作生成tree.cpio文件,当find查找时自然而然把该文件压缩到自己的目录中

把当前的文件归档到tree1.cpio里面,tree.cpio里面有本身

[root@localhost name]# find ./ -depth |cpio -ov -F tree1.cpio

把当前的文件归档到/tmp/目录下

[root@localhost name]# find ./ -depth |cpio -ov -F /tmp/tree.cpio

–null 解析空字符

[root@localhost name]# find ./ -depth -print0 |cpio --null -ov -F /tmp/tree2.cpio

查看tree1.cpio下的归档内容

-t:查看归档内容

-F:指定归档文件

[root@localhost name]# cpio -t -F tree1.cpio
root@localhost name]# cpio -t < tree1.cpio

查看home1.cpio归档文件里的/root/下的内容(没有隐藏文件)

cpio -t -F /tmp/home1.cpio /root/*

查看home1.cpio归档文件里的/root/下的内容(全是隐藏文件)

cpio -t -F /tmp/home1.cpio /root/.*

查看home1.cpio归档文件里的/root/下的内容(查看所有文件)

cpio -t -F /tmp/home1.cpio /root/{.*,*}

向归档文件中追加文件

-o:表示copy-out模式

-A:追加新文件

[root@localhost tmp]# ls /root/test.txt |cpio -oA -F /tmp/home.cpio

添加新目录

[root@localhost tmp]# find /boot -depth -print0 |cpio -oA -F /tmp/home.cpio

提取文件

-i:copy-in模式,代表提取

-d:需要时自动创建目录

-v:显示详细信息

[root@localhost tmp]# cpio -idv -F /tmp/home.cpio

复制~下的文件到/tmp/abc/root/

-p:copy-pass模式

[root@localhost root]# find ~ -depth -print0 | cpio --null -pvd /tmp/abc

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值