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
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值