cpio command in Linux with Examples

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


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.