cpio命令

RPM包中文件提取

cpio命令主要有三种基本模式:"-o"模式指的是copy-out模式,就是把数据备份到文件库中;"-i"模式指的是copy-in模式,就是把数据从文件库中恢复;"-p"模式指的是复制模式,就是不把数据备份到cpio库中,而是直接复制为其他文件。

cpio -o[vcB] > [文件|设备]

    -o    copy-out模式,备份
    -v    显示备份过程
    -c    使用较新的portable format存储方式
    -B    设定输入输出块为5120bytes,而不是模式的512butes

cpio -i[vcdu] < [文件|设备]
    
    -i    copy-i模式,还原
    -v    显示还原过程
    -c    使用较新的portable format存储方式
    -d    还原时自动新建目录
    -u    自动使用较新的文件覆盖较旧的文件

cpio -p 目标目录
使用cpio备份数据的方法
[root@centos2 ~]# find /etc -print | cpio -ovcB > /root/etc.cpio [root@centos2 ~]# ll -h etc.cpio -rw-r--r-- 1 root root 35M 11月 6 20:18 etc.cpio
恢复cpio的备份数据
[root@centos2 ~]# cpio -idvcu < /root/etc.cpio

如果备份时使用绝对路径,则恢复的数据会直接到绝对路径指定的路径中,如果需要把数据恢复到当前目录中,则需要使用相对路径

[root@centos2 ~]# cd /etc/
[root@centos2 ~]# find . -print |cpio -ovcB > /root/etc.cpio
#进入到,利用find指定要备份/etc/目录,使用>导出到etc.cpio文件

[root@centos2 ~]# cd /root
[root@centos2 ~]# mkdir etc_test
[root@centos2 ~]# cd etc_test/
[root@centos2 ~]# cpio -ivdcu < /root/etc.cpio
#还原/etc目录的数据,因为备份时使用的是相对路径,则会还原到/root/etc_test/目录下

cpio -p 复制模式

[root@centos2 /tmp]# mkdir test
[root@centos2 /tmp]# find /boot/ -print | cpio -p /tmp/test
[root@centos2 /tmp]# ll test/
总用量 4
dr-xr-xr-x 5 root root 4096 11月  6 20:31 boot

提取RPM包中文件

rpm2cpio 包全名 | cpio -idv .文件绝对路径

    rpm2cpio    将rpm包转换为cpio格式的命令
    cpio
[root@centos2 ~/etc_test]# rpm -qf /etc/inittab 
initscripts-9.49.47-1.el7.x86_64
[root@centos2 ~/etc_test]# rpm2cpio /mnt/cdrom/
EFI/      images/   isolinux/ LiveOS/   Packages/ repodata/ 
[root@centos2 ~/etc_test]# rpm2cpio /mnt/cdrom/
EFI/      images/   isolinux/ LiveOS/   Packages/ repodata/ 
[root@centos2 ~/etc_test]# rpm2cpio /mnt/cdrom/Packages/initscripts-9.49.47-1.el7.x86_64.rpm | cpio -idv ./etc/inittab
./etc/inittab
3046 块
[root@centos2 ~/etc_test]# ll
总用量 0
drwxr-xr-x 2 root root 21 11月  6 20:48 etc
[root@centos2 ~/etc_test]# ll etc/
总用量 4
-rw-r--r-- 1 root root 511 11月  6 20:48 inittab

猜你喜欢

转载自www.cnblogs.com/sswind/p/11832969.html
今日推荐