Create, view, and extract an archive using the CPIO command in Linux

Home > Search > Linux commands
  by

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

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




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




Comments