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