`

copy file using cpio

阅读更多

http://bradthemad.org/tech/notes/cpio_directory.php

Most people live their whole lives without ever using the cpio utility. However, it is a useful thing, and is sometimes better suited to copying lots of files around than tar or cp. Here's a quick primer.

Some important flags

(In case the man-page wasn't clear enough)

-o
Copy out mode: Read in files from disk, output is a cpio stream or file, similar to "tar -c"
-i
Copy in mode: Read cpio archive file or stdin, extract as files to disk, similar to "tar -x"
-p
Pass-thru mode: Like piping cpio -o into cpio -i
-V
Verbose mode: Prints a dot for each file processed (all modes)
-O
Outfile: Specify an archive file rather than stdout (copy-out mode)
-d
Creates leading directories where needed when extracting files (copy-in and pass-thru modes)
-a
Resets atime on files being read, so the original files won't appear to have just been accessed (copy-in and pass-thru modes)
-m
Preserves original mtime on files being written out, so the copy will have the same timestamps as the original (copy-out and pass-thru modes)

Basic usage

Create a cpio archive:

localhost%

 find path/ -depth -print | cpio -oaV > archive.cpio
localhost%

 find path/ -depth -print | cpio -oaV -O archive.cpio

Create a cpio archive and compress it:

localhost%

 find path/ -depth -print | cpio -oaV | gzip -c > archive.cpio.gz

Extract a cpio archive:

localhost%

 cpio -imVd < archive.cpio
localhost%

 cpio -imVd -I archive.cpio

List the contents of a cpio archive:

localhost%

 cpio -it < archive.cpio
localhost%

 cpio -it -I archive.cpio

Use cpio copy-pass to copy a directory structure to another location:

localhost%

 find path/ -depth -print | cpio -pamVd /new/parent/dir

Pathnames

Avoid using pathnames starting with /, as that can be inflexible and possibly messy when extracting an archive. Good practice is to change to the directory above the one you're copying. That way, extracted files will go into their own directory, rather than the current directory, much like a well-behaved source tarball. For example:

localhost%

 pwd
/usr/src/linux-2.4
localhost%

 cd ..
localhost%

 find linux-2.4/ -depth -print | cpio -oaV -O linux-2.4.cpio

cpio over ssh

To cpio a local directory, send the output to ssh and feed it to cpio on a remote host:

localhost%

 find path/ -depth -print | cpio -oaV | ssh user@host 'cpio -imVd'

Ssh to a remote host, cpio a remote directory, and get its output locally:

localhost%

 ssh user@host "find path/ -depth -print | cpio -oaV" | cpio -imVd

cpio and rpm

Ever wanted to extract files from an RPM package without installing it? It's easy. RPMv4 includes a utility called "rpm2cpio", which creates a cpio stream of files from a given RPM. You can pipe this into cpio just like a regular archive or stream.

List the included files:

localhost%

 rpm2cpio foo.rpm | cpio -it
./usr/bin/foo
./usr/share/man/man1/foo.1.gz
39 blocks

Note that the pathnames in the cpio stream begin with "./" -- this is important to know if you want to name specific files to extract.

Extract all files:

localhost%

 rpm2cpio foo.rpm | cpio -imVd
..
39 blocks

Extract only the manpage from that package:

localhost%

 rpm2cpio foo.rpm | cpio -imVd ./usr/share/man/man1/foo.1.gz
分享到:
评论

相关推荐

    linux命令cpio用法详解

    -E&lt;范本文件&gt; 或 --pattern-file=&lt;范本文件&gt;:指定范本文件,其内含有一个或多个范本样式,让 cpio 解开符合范本条件的文件,格式为每列一个范本样式。 -f 或 --nonmatching:让 cpio 解开所有不符合范本条件的文件...

    cpio2.9命令源代码,讲述了文件如何压缩

    cpio -i [ -6AbBcdfkmnqrsStTuvV ] [-C bufsize ] [ [ -I file [, file ... ] ] [ -M message ] ] [ -Pifd,ofd ] [ pattern ... ] cpio -p [ -adlLmruvV ] [ -Pifd,ofd ] directory 描述 (DEscriptION)  cpio...

    linux下的dd和cpio命令.pdf

    cpio 命令的选项包括:-o 将资料 copy 输出到文件或装置上、-i 将资料自文件或装置 copy 出来系统当中、-t 查看 cpio 建立的文件或装置的内容、-c 一种较新的 portable format 方式储存、-v 让储存的过程中文件名称...

    cpio命令详解

    - **Copy-In 模式**: 在此模式下,`cpio` 从归档文件中读取文件并将其提取到文件系统中。通过 `-i` 选项指定。 - **Copy-Pass 模式**: 此模式用于在两棵树之间复制文件,无需使用归档文件。通过 `-p` 选项指定。 ...

    cpio命令使用

    `cpio`命令提供了三种基本操作模式:copy-out(-o)、copy-in(-i)和pass-through(-p)。下面我们将详细介绍这三种模式及其相关的参数和使用实例。 1. **copy-out模式(-o)**: 这种模式用于创建归档文件。`...

    解压cpio文件

    ### 解压cpio文件 在Linux环境中,`cpio`是一种常见的用于归档文件的工具。它可以用来创建、查看和提取归档文件。本篇内容将详细介绍如何解压`cpio`格式的文件,特别是那些经过gzip压缩的文件。 #### 一、基本概念...

    initrd.img.cpio

    直接将此cpio文件系统包含进kernel即可启动! 也可用好压在xp下解压,即可的文件系统!

    normal-cpio-client.cpio

    normal-cpio-client.cpio

    cpio解压缩加自动脚本.zip

    1.移动读取.bat 文件 到非中文需压缩目录内 2.双击 移动读取.bat 生成1.txt ...4.移动 libiconv2.dll、libintl3.dll、压缩.cmd、cpio.exe 到非中文需压缩目录内 5.双击 压缩.cmd 等待生成 message.cpio

    cpio:Rust中独立的CPIO文件阅读器

    CPIO(Copy In/Out)是一种古老的档案格式,广泛用于Unix和类Unix系统中,用于打包和归档文件。"newc"格式是CPIO的一种变体,是较新的格式,它采用了更简单的记录结构,使其更容易解析。在Rust的生态系统中,创建一...

    cpio-2.10-10.el6.i686.rpm

    cpio-2.10-10.el6.i686.rpm是centos工具包。

    10201_database_linux_x86_64.cpio

    oracle 10G_database_linux_x86_64

    cpio 解压

    解压网上介绍较多,不多说,重新压缩,网上介绍的不是WINDOWS系统下的,在WINDOWS下,建一文件夹, 把把本解压文件和meesage放入该文件夹, 第一步,解压,双击:解压.cmd 第二步,读取文件,双击:读取文件.cmd 生成...

    Linux cpio命令用法详解

    Linux cpio命令 Linux cpio命令用于备份文件。 cpio是用来建立,还原备份档的工具程序,它可以加入,解开cpio或tra备份档内的文件。 语法 cpio [-0aABckLovV][-C ][-F ][-H ][-O ][--block-size=][--force-local][-...

    perl-Archive-Cpio

    《perl-Archive-Cpio:Perl语言中的CPIO存档处理模块》 在Perl的世界里,`perl-Archive-Cpio`是一个用于处理CPIO存档格式的模块。CPIO是一种广泛使用的档案格式,常用于在Unix和类Unix系统中备份和传输文件。这个...

    cpio-2.12-10.el8.x86_64.rpm

    离线安装包,亲测可用

    10gr2_aix5l64_client.cpio.zip.002

    10gr2_aix5l64_client.cpio.zip.002

    10gr2_aix5l64_client.cpio.zip.001

    10gr2_aix5l64_client.cpio.zip.001

    10gr2_aix5l64_database.cpio.zip.001

    10gr2_aix5l64_database.cpio.zip.001

Global site tag (gtag.js) - Google Analytics