cpio

最後更新: 2021-03-10

介紹

cpio 一共有 3 個 mode, 分別是

  • copy-out        # file->archive
  • copy-in          # archive->file
  • Copy-pass      # directory_tree->directory_tree)

copy-out(-o)

Writes the archive onto the stdout
(unless overridden by the --file option)

copy-in(-i)

Reads the archive from the standard input

Copy-pass(-p)

Combining the copy-out and copy-in steps without actually using an archive

 


Syntax

 

cpio {-p|--pass-through} destination-directory < name-list

Opts

'-0, --null'

Read a list of filenames terminated by a null character, instead of a newline,

so that files whose names contain newlines can be archived.

--format X

newc

The new (SVR4) portable format, which supports file systems having more than 65536 i-nodes. (4294967295 bytes)

crc

The new (SVR4) portable format with a checksum added.

ustar

The  POSIX.1 tar format.  Also recognizes GNU tar archives

'-v, --verbose'

Verbosely list the files processed.

'-A, --append'

Append to an existing archive.

The archive must be a disk file specified with the -O or -F (-file) option.

'-F/-O, --file=archive'

Archive filename to use instead of standard input or output.

To use a tape drive on another machine as the archive, use a filename that starts with 'HOSTNAME: '.

The hostname can be preceded by a username and an '@' to access the remote tape drive as that user,

if you have permission to do so (typically an entry in that user's '~/.rhosts' file).

'--force-local'

With -F, -I, or -O, take the archive file name to be a local file even if it contains a colon, which would ordinarily indicate a remote host name.

'-B'

Set the I/O block size to 5120 bytes. Initially the block size is 512 bytes.

相當於 '--block-size=10'

'--block-size=BLOCK-SIZE' Set the I/O block size to BLOCK-SIZE * 512 bytes.

'-u, --unconditional'

Replace all files, without asking whether to replace existing newer files with older files.

'--sparse'

Write files with large blocks of zeros as sparse files. This option is used in copy-in and copy-pass modes.

'--only-verify-crc'

Verify the CRC 's of each file in the archive, when reading a CRC format archive. Don't actually extract the files.

'-R [user][:.][group], --owner [user][:.][group]'

Set the ownership of all files created to the specified user and/or group in copy-out and copy-pass modes.

Either the user, the group, or both, must be present. If the group is omitted but the ':' or '.' separator is given,

use the given user's login group. Only the super-user can change files' ownership.

'--no-preserve-owner'

Do not change the ownership of the files; leave them owned by the user extracting them. This is the default for non-root users

'--no-absolute-filenames'

Create all files relative to the current directory in copy-in mode, even if they have an absolute file name in the archive.

'--absolute-filenames' (default)

Do not strip leading file name components that contain '..' and leading slashes from file names in copy-in mode

'-m, --preserve-modification-time'

Retain previous file modification times when creating files.

find . -print -depth | cpio -ov > tree.cpio

'-depth'

option forces 'find' to print of the entries in a directory before printing the directory itself.

This limits the effects of restrictive directory permissions by printing the directory entries in a directory before the directory name itself.

find . -depth -print0 | cpio --null -pvd new-dir

'-print0' available with GNU find, combined with the '--null' option of cpio. These two options act together to send file names between find and cpio, even if special characters are embedded in the file names

 

--- find 的補充 ---

-d A synonym for -depth, for compatibility with FreeBSD, NetBSD, MacOS X and OpenBSD.

-depth Process each directory's contents before the directory itself.

Use of -delete automatically turns on the `-depth' option.