System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

Extract a directory path and contents from a CPIO Archive

SOLVED
Go to solution
Alzhy
Honored Contributor

Extract a directory path and contents from a CPIO Archive

I can extract a single file:

cpio -ivdm opt/soft/config.txt
But how do I extract the entrore contents of /opt/soft/* and subdirs, etc... without sing a list file?

Hakuna Matata.
3 REPLIES
Matti_Kurkela
Honored Contributor
Solution

Re: Extract a directory path and contents from a CPIO Archive

cpio accepts wildcards, but you must protect them with quotes or backslashes so that the shell won't attempt to expand the wildcards before executing the command line:

cpio -ivdm "opt/soft/*" or
cpio -ivdm 'opt/soft/*' or
cpio -ivdm opt/soft/\*
This is a standard feature of unix-style shells. Whenever you need the wildcards to apply to something that is either not local or not yet present in the filesystem when the command starts, you'll usually need to quote or backslash your wildcards.

MK
MK
James R. Ferguson
Acclaimed Contributor

Re: Extract a directory path and contents from a CPIO Archive

Hi:

The 'cpio' utility understands pattern matching notation used by the shell. To avoid having the shell interpret and expand that pattern, escape with a backslash character every meta-character.

Thus, '/opt/soft/*' would need to be written as '/opt/soft/\*'.

Regards!

...JRF...

Dennis Handly
Acclaimed Contributor

Re: Extract a directory path and contents from a CPIO Archive

>how do I extract the entire contents of /opt/soft/* and subdirs, etc... without using a list file?

The same as for a single file. Or you use pax(1) instead.
pax -r -v -f archive opt/soft

>MK: cpio accepts wildcard
>JRF: The 'cpio' utility understands pattern matching notation

Not sure why you would need them? Just provide the upper directory.