Bootstrap FreeKB - Linux Commands - cpio (create, view, and extract an archive)
Linux Commands - cpio (create, view, and extract an archive)

Updated:   |  Linux Commands articles

The cpio command can be used to create or extract an archive. 


Create an archive

The -o or --create option can be used to create an archive. In this example, the contents of the /etc directory are stored in an archive named example.cpio.

[john.doe@server1 ~]# find /etc/* | cpio -o > /home/john.doe/example.cpio

 

Instead of using the > character, the -O option can be used.

[john.doe@server1 ~]# find /etc/* | cpio -o -O /home/john.doe/example.cpio

 

The -v or --verbose option can be used to display the files being added to the archive.

[john.doe@server1 ~]# find /etc/* | cpio -ov > /home/john.doe/example.cpio
/etc/adjtime
/etc/aliases
/etc/aliases.db
. . .

 


View the contents of an archive

The -i or --extract and and -t or --list options can be used to view the contents of an archive. In this example, the contents of the example.cpio archive is displayed.

[john.doe@server1 ~]# cpio -it < /home/john.doe/example.cpio
/etc/adjtime
/etc/aliases
/etc/aliases.db
. . .

 

Instead of using the < character, the -I option can be used.

[john.doe@server1 ~]# cpio -it -I /home/john.doe/example.cpio
/etc/adjtime
/etc/aliases
/etc/aliases.db
. . .

 


Extract an archive

The -i or --extract option without the -t or --list options can be used to extract the contents of an archive.

[john.doe@server1 ~]# cpio -i < /home/john.doe/example.cpio

 

The -d or --make-directories and -u or --unconditional options can be used to create and overwrite the files in a directory during an extraction.

[john.doe@server1 ~]# cpio -idu < /home/john.doe/example.cpio

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter d9da98 in the box below so that we can be sure you are a human.