I have a cpio archive with lots of files and I need to extract only one file, not all. With tar I could just use tar -xf archive.tar path/to/file, but that does not work with cpio:

cpio -i < archive.cpio path/to/file
bash: path/to/file: No such file or directory

Does anyone know how to extract just a single file from a cpio archive?

1 Answer 1


You should use the -d option to let cpio create the leading directories (path/to) if they don't exist:

cpio -id < archive.cpio path/to/file

Also, bsdtar (the regular tar on FreeBSD) knows how to extract cpio archives, whether compressed or not.

  • Make sure to OMIT the leading forward slash on the /path/to/file... I mean... path/to/file... or it will not work! Also, you can include more than one file with spaces in between them, just in case you want to extract TWO files.
    – Brain2000
    Oct 22, 2020 at 4:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.