cpio: Creates an archive or restores files from an archive
Format
cpoi --create [options]
cpoi --extract [options] [patterns]
copi --pass-through [options] directory
Description
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.
Arguments
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.
Options
Major Options
Three options determine the mode in which cpio operates. You must include exactly one of these options whenever you use cpio.
--extract -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 :
$ cpio -i \*.c < /dev/st0
The backslash prevents the shell from expanding the * before it passes the argument to cpio.
--create -o
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:
$ find / -depth -print | cpio -o > /dev/st0
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.
--pass-through -p
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:
$ find . -depth -print | cpio -pdm ~alex/code
Other Options
The remaining options alter the behavior of cpio. These options work with one or more of the preceding major options.
--reset-access-time -a
Resets the access times of source files after copying them so that they have the same access time after copying as they did before.
-B
Sets the block size to 5,120 bytes instead of the default 512 bytes.
--block-size=n
Sets the block size used for input and output to n * 512-byte blocks.
--make-directories -d
Create leading directories where needed.
--file=archive -F
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.
--preserve-modification-time -m
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.
--list -t
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.
--verbose -v
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.
Examples:
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:
$ find /home/jenny -depth -print | cpio -oB > /dev/ftape
To check the contents of the archive file and display a detailed listing of the files it contains, use
$ cpio -itv < /dev/ftape
The following command restores the files that formerly were in the memo subdirectory of Jenny's home directory:
$ cpio -idm /home/jenny/memo/\* < /dev/ftape
分享到:
相关推荐
"Linux 下的 dd 和 cpio 命令" Linux 下的 dd 命令是非常有用的命令,它可以用指定大小的块拷贝一个文件,并在拷贝的同时进行指定的转换。dd 命令直接调用硬盘驱动复制的,所以说速度上会很快。语法:dd [选项] if=...
Linux cpio命令 Linux cpio命令用于备份文件。 cpio是用来建立,还原备份档的工具程序,它可以加入,解开cpio或tra备份档内的文件。 语法 cpio [-0aABckLovV][-C ][-F ][-H ][-O ][--block-size=][--force-local][-...
### cpio命令详解 #### 概述 `cpio` 是 Linux 和类 Unix 系统中用于处理归档文件的强大工具。它支持多种格式,并且能够处理文件的存入(copy-out)、读取(copy-in)以及从一个目录树复制到另一个目录树(copy-pass...
Linux 命令 cpio 用法详解 cpio 是一个用于建立、还原备份档的工具程序,可以加入、解开 cpio 或 tar 备份档内的文件。下面将详细讲解 cpio 命令的用法,包括各种选项和参数的解释。 基本语法 cpio 命令的基本...
cpio命令主要是用来建立或者还原备份档的工具程序,cpio命令可以复制文件到归档包中,或者从归档包中复制文件。 语法格式: cpio [参数] 常用参数: -0 接受新增列控制字符,通常配合find指令的“-print0”参数...
`cpio`命令是Linux系统中用于文件和目录备份与恢复的一个工具,它允许用户将文件和目录结构存入归档文件,或者从归档文件中恢复文件。`cpio`命令提供了三种基本操作模式:copy-out(-o)、copy-in(-i)和pass-...
Linux 操作系统中有多种打包命令,包括 cpio 和 tar 等,这些命令可以将多个文件或目录打包成一个文件库,然后使用 compress 命令将其压缩,以达到存储和备份的目的。本文将详细介绍 cpio 和 tar 两个命令的使用方法...
cpio 命令是一个备份和恢复命令。其语法为: ``` cpio [-ovc] [file|device] ``` 参数: * -o:备份参数 * -v:显示备份进度 * -c:使用补丁 例如: ``` [root@localhost Desktop] find | cpio -ovcB /home/oracle...
在备份文件方面,cpio命令是一个非常强大的工具,它能够创建、还原备份档,支持多种备份格式,包括cpio和tar格式。通过cpio命令的多种参数,用户可以控制备份的行为,如设置区块大小、指定备份档的名称、处理目录...
- cpio命令用于创建归档文件或从归档文件中提取文件。 以上列举的命令只是Linux命令大全中的一小部分。实际上,Linux命令行工具十分丰富,涵盖了从系统管理、网络配置、文本处理、文件操作到程序开发等多个方面。...
3. cpio命令:cpio命令也是通过拷贝的方式实现文件或文件系统的备份与恢复。它与tar的不同之处在于它能通过重定向以及管道操作,可以将文件发送给外部设备。 具体的备份命令和操作方法将在下文中介绍。 3.2 tar...
2. cpio 命令:用于解压 *.cpio 类型的文件。 3. tar 命令:用于解压 *.tar 类型的文件。 4. jar 命令:用于解压 *.zip 类型的文件。 六、目录管理命令 1. mkdir 命令:用于创建一个或多个新的目录。 2. mv 命令:...
* `-cpio`:对匹配的文件使用 cpio 命令,将他们备份到磁带设备中。 * `-prune`:忽略某个目录。 实践应用 下面是一些常用的 `find` 命令实践应用: * 查找当前目录下的所有文件:`find . -type f` * 查找当前...
cpio - 存取归档包中的文件 语法 Syntax cpio -o [ -aBLuvV ] [ -C bufsize ] [ -c | -H format ][ -K volumesize ] [ [ -O file [, file ... ] ] [ -M message ] ] [ -Pifd,ofd ] cpio -i [ -6...
gunzip、unzip命令用于解压缩文件,而cpio命令可以用来复制归档文件。此外,zip和unzip命令与Windows平台上的同名工具相似,方便在不同操作系统间共享文件。 3. 文件管理命令 Linux系统中,文件管理命令主要用来...
本文介绍了tar命令、gzip, zcat 命令、bzip2, bzcat 命令、compress 命令、dd 命令、cpio 命令,具体如下: tar命令 解压文件到指定目录: tar -zxvf /home/zjx/aa.tar.gz -C /home/zjx/pf tar [-cxtzjvfpPN] ...
4. **cpio**:cpio命令可以创建多卷备份,并且能够处理ls或find命令的输出,将文件写入磁带。它的选项包括-o(输出)和-i(输入)。cpio在文件之间插入标题以方便恢复,但速度较tar慢。它可以使用通配符,但其匹配...