The quick way to CPIO

<script type="text/javascript"> </script> <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script>

 

Like the TAR command, CPIO is used to backup or archive files and directories.

The difference is that tar by default backup file to a tape device and backup all of a specified directory, whereas cpio by default archive only the files you tell it to using command line arguments. That’s why it’s always (almost) used with other command to do backup/archive.

To start with, backup a directory under /home/acheng/www:

#cd /home/acheng/www

#find -d . | cpio -ovF ../wwwbak.cpio

When using the find utility with cpio, it is always a good idea to include either the d or the depth switch. This switch prevented permissions from interfering with a backup. When using this switch, either put -d right after the word find and before the directory to search (in this case, “.“), or put the word -depth after the directory to search, like so:

#find . -depth -print | cpio -ov > backup.cpio

To view the contents of a cpio archive without extracting, use:

# cpio -it < ../wwwbak.cpio

To extract, use:

#mkdir ../restore;cd ../restore

#cpio -ivd < ../wwwbak.cpio

Note the d switch, it tell cpio to create any dir when necessary. otherwise it’ll compain not being able to find the dir to restore to.

You can also use -p switch to let cpio emulate what cp can do with a directory or file, that is to copy them over to a different place.

The benefit of using cpio instead of cp is that you can fine tune the files/dirs you want to copy with utilities like FIND and you can reserve a file’s create time/modified time, plus you can reserve/change a file’s ownership at wish.

Let’s say you want to backup the www dir to /tmp:

#cd /home/acheng/www

#find -d . | cpio -pvd /tmp

Or change the ownership of all copied files to user alan:

#find -d . | cpio -pvd -R alan /tmp

To reserve all original time of these files, use:

#find -d . | cpio -pvdam -R alan /tmp

** use “man cpio” for more information and options with cpio

–end–

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值