Open In App

cpio command in Linux with Examples

Last Updated : 15 May, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

cpio stands for “copy in, copy out“. It is used for processing the archive files like *.cpio or *.tar. This command can copy files to and from archives.

Synopsis:

  • Copy-out Mode: Copy files named in name-list to the archive

    Syntax:

    cpio -o < name-list > archive
  • Copy-in Mode: Extract files from the archive

    Syntax:

    cpio -i < archive
  • Copy-pass Mode: Copy files named in name-list to destination-directory

    Syntax:

    cpio -p destination-directory < name-list

Policy Options:

  • -i, –extract: Extract files from an archive and it runs only in copy-in mode.
  • -o, –create: Create the archive and it runs only in copy-out mode.
  • -p, –pass-through: Run in copy-pass mode.
  • -t, –list: Print a table of contents of all the inputs present.

Operation modifiers valid in any Mode:

  • -B: Changes the I/O block size to 5120 bytes.
  • -c: Use the old portable (ASCII) archive format.
  • -C, –io-size=NUMBER: Set the I/O block size to the given particular NUMBER of bytes.
  • -D, –directory=DIR: Changes to Directory DIR.
  • -H, –format=FORMAT: Use given arc.
  • -v, –verbose: List the files processed in a particular task.
  • -V, –dot: Print “.” for each file processed in a particular task.
  • -W, –warning=FLAG: Control warning display. Currently FLAG is one of ‘none‘, ‘truncate‘, ‘all‘.

Examples:

  • To create a *.cpio file : We can create *.cpio files containing files and directory with the help of cpio command.

    Syntax:

    cpio -ov < name-list > archive

    Here -ov is used as -o create the new archive and -v list the files processed.

  • To extract a *.cpio file: We can extract *.cpio files containing files and directory with the help of cpio command.

    Syntax:

    cpio -iv < archive

  • To create *.tar archive file using cpio: The cpio helps to create a *.tar archive.

    Syntax:

    cpio -ov -H tar > archive

  • To extract *.tar archive file using cpio: The cpio helps to extract *.tar files containing files and directory.

    Syntax:

    cpio -iv -F < archive

  • To create a *.cpio archive with selected files: We can create *.cpio files containing specific files with the help of cpio command. In the example we are using .txt files.

    Syntax:

    find . -iname "*.txt" | cpio -ov > archive

  • To create a *.tar archive with selected files: We can create *.tar files containing specific files with the help of cpio command. In the example we are using .txt files.

    Syntax:

    find . -iname "*.txt" | cpio -ov -H tar > archive

  • To only view *.tar archive file using cpio: The cpio helps to view *.tar files containing files and directory.

    Syntax:

    cpio -it -F < archive

Note:

  • To check for the manual page of cpio command, use the following command:
     man cpio
  • To check the help page of cpio command, use the following command:
     cpio --help

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads