cpio命令

[size=large][align=center][b]cpio: Creates an archive or restores files from an archive[/b][/align]
[b]Format[/b]
[i]cpoi --create [options]
cpoi --extract [options] [patterns]
copi --pass-through [options] directory[/i]

[b]Description[/b]
The cpio utility has three modes of operation: Create mode places multiple files into a single archive file, extract mode restores files from an archive, and pass-through mode copies a directory hierarchy to another location. The archive file used by cpio may be saved on disk, tape, other removable media, or a remote system.

Create mode reads a list of ordinary or directory filenames from standard input and writes the resulting archive file to standard output. You can use this mode to create an archive. Extract mode reads the name of an archive from standard input and extracts files from that archive. You can decide to restore all the files from the archive or only those whose names match specific patterns. Pass-through mode reads ordinary or directory filenames from standard input and copies the files to another location on the disk.

[b]Arguments[/b]
By default cpio in extract mode extracts all files found in the archive. You can choose to extract files selectively by supplying one or more patterns. If the name of a file in the archive matches one of the patterns, that file is extracted; otherwise, it is ignored. The cpio patterns are similar to shell wildcards except that patterns match slashes (/ ) and a leading period (.) in a filename.

In pass-through mode you must give the name of the target directory as an argument to cpio.

[b]Options[/b]
[b]Major Options[/b]
Three options determine the mode in which cpio operates. You must include exactly one of these options whenever you use cpio.

[i][b]--extract -i[/b][/i]
Reads the archive from standard input and extracts files. Without any patterns on the command line, cpio extracts all the files from the archive. With patterns specified, cpio extracts only files with names the patterns match. The following example extracts from the SCSI tape at /dev/st0 only those files whose names end in .c :
$ [i]cpio -i \*.c < /dev/st0[/i]
The backslash prevents the shell from expanding the * before it passes the argument to cpio.

[i][b]--create -o[/b][/i]
Constructs an archive from the files named on standard input. These files may be ordinary or directory files, and each must appear on a separate line. The archive is written to standard output as it is built. The find utility frequently generates the filenames that cpio uses. The following command builds an archive of the entire local system and writes it to the SCSI tape at /dev/st0:
$ [i]find / -depth -print | cpio -o > /dev/st0[/i]
The -depth option causes find to search for files in a depth-first search, reducing the likelihood of permissions problems when you restore the files from the archive.

[b][i]--pass-through -p[/i][/b]
Copies files from one place on the system to another. Instead of constructing an archive file containing the files named on standard input, cpio copies them into the directory (the last argument given to cpio). The effect is the same as if you had created an archive with copy-out mode and then extracted the files with copy-in mode, but using pass-through mode avoids creating an archive. The following example copies the files in the working directory and all subdirectories into /home/alex/code:
$ [i]find . -depth -print | cpio -pdm ~alex/code[/i]

[b]Other Options[/b]
The remaining options alter the behavior of cpio. These options work with one or more of the preceding major options.

[i][b]--reset-access-time -a[/b][/i]
Resets the access times of source files after copying them so that they have the same access time after copying as they did before.

[i][b]-B[/b][/i]
Sets the block size to 5,120 bytes instead of the default 512 bytes.

[i][b]--block-size=n[/b][/i]
Sets the block size used for input and output to n * 512-byte blocks.

[i][b]--make-directories -d[/b][/i]
Create leading directories where needed.

[i][b]--file=archive -F[/b][/i]
Uses archive as the name of the archive file. In extract mode, reads from archive instead of standard input. In create mode, writes to archive instead of standard output. You can use this option to access a device on another system on a network.

[i][b]--preserve-modification-time -m[/b][/i]
Preserves the modification times of files that are extracted from an archive. Without this option the files show the time they were extracted. With this option the created files show the time they had when they were copied into the archive.

[i][b]--list -t[/b][/i]
Displays a table of contents of the archive. This option works only with the --extract option, although no files are actually extracted from the archive. With the --verbose option, it displays a detailed table of contents in a format similar to that used by ls -l.

[i][b]--verbose -v[/b][/i]
Lists files as they are processed. With the list option, it displays a detailed table of contents in a format similar to that used by ls -l.

[b]Examples:[/b]
The first example creates an archive of the files in Jenny's home directory, writing the archive to a tape drive supported by the ftape driver:
$ [i]find /home/jenny -depth -print | cpio -oB > /dev/ftape[/i]

To check the contents of the archive file and display a detailed listing of the files it contains, use
$ [i]cpio -itv < /dev/ftape[/i]

The following command restores the files that formerly were in the memo subdirectory of Jenny's home directory:
$ [i]cpio -idm /home/jenny/memo/\* < /dev/ftape[/i][/size]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
cpio命令的使用 利用cpio 可将文件或目录从文件库获取出来或将数据拷贝到文件库。 cpio 的指令格式: cpio –i[bcdmrtuv] [patterns] cpio –o [abcv] cpio –p [adlmuv][directory] 说明:cpio 共有三种基本模式,-o即copy-out 模式,将一组文件copy到一个文件库,-i 即copy-in 模式,读取文件库,并将其展开在当前目录,-p 能从某个目录读取所有文件(包括子目录到另一个目录),且不以archive(归档)的方式存放。 cpio 常配合shell使用。-o常用标准输入设备读取要copy 的文件名称,并将copy成的archive file 通过标准输出设备输出。一般利用输入/输出重定向或管道的原理,达到真正复制的功能。 (一)利用cpio备份: [例1] $ find work –print | cpio –ocdv > /dev/rfd0135ds18 将work目录下的文件备份到软盘上。-o表示输出模式,-c生成一个带有头信息的文件。 -d表示按需要生成目录,-v表示命令执行时不断显示信息。用“>”把结果定向到软盘。 [例2] $ ls |cpio –o >/usr/linfs/old1 将当前目录下的所有文件复制成old1 archive file [例3] $ ls *.c | cpio –o>oldc 复制工作目录中的所有的c程序. [例4] $ ls| cpio –p /usr/linfs/tempdir 复制当前工作目录下的文件到/usr/linfs/tempdir 目录,不生成archive file . (二)利用cpio 复原: [例5] $ cpio –icdv < /dev/rfd0135ds18 将软盘中的文件复原。-i告诉cpio把文件作为它的输入,-d按需要生成目录,-v显示执行时的所有信息,-c具有头文件格式。 [例6] $ cpio –icdv "*stat.wp" < /dev/rfd0135ds18 仅复原*stat.wp的文件 [例7] $ cpio –i </usr/linfs/old1 *.f 仅复原*.f 文件
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值