cpio command in Linux with Examples

15 May, 2019
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 archiveSyntax:cpio -o < name-list > archive
Syntax:
cpio -o < name-list > archive
Copy-in Mode: Extract files from the archiveSyntax:cpio -i < archive
Syntax:
cpio -i < archive
Copy-pass Mode: Copy files named in name-list to destination-directorySyntax:cpio -p destination-directory < name-list
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 > archiveHere -ov is used as -o create the new archive and -v list the files processed.
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
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
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
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
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
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
Syntax:
cpio -it -F < archive
Note:
To check for the manual page of cpio command, use the following command: man cpio
 man cpio
To check the help page of cpio command, use the following command: cpio --help
 cpio --help
linux-command
Linux-file-commands
Picked
Linux-Unix
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Docker - COPY Instruction
scp command in Linux with Examples
chown command in Linux with Examples
Introduction to Linux Operating System
SED command in Linux | Set 2
nohup Command in Linux with Examples
Array Basics in Shell Scripting | Set 1
mv command in Linux with examples
chmod command in Linux with examples
Basic Operators in Shell Scripting