4

I am trying to copy a single file from a .cpio file, to a different directory rather than the tree inside it. I am trully sure it is possible, my teacher did it.

I have tried this:

# cpio -i -F backup.cpio sub1/sub2/example.php

But that doesn't extract the file example where I want it to be extracted. I tried adding a third parameter but it doesn't work. Any suggestions? Oh, and I'm running Ubuntu.

jcollado
  • 39,419
  • 8
  • 102
  • 133
MoeSzislak
  • 137
  • 1
  • 4
  • 13

1 Answers1

8

One way to do it would be to extract that single file to stdout and redirect it to the file of your choice:

cpio -i --to-stdout sub1/sub2/example.php < backup.cpio > new_filename.php
jcollado
  • 39,419
  • 8
  • 102
  • 133
  • Was hoping just `-i` could extract a file I match with a pattern not using stdout, but I only have it working adding both that switch and `--to-stdout` where I would have to specify the name manually. Every time I only use the 1 switch, it says `No such file or directory`. I normally use the path prefix `./` in the working case, but tried other combinations for the non-working one without success,. The man page says this tool is legacy, but I've tried 7z and I need that to read archives on stdin, but it returns E_NOTIMPL.. – Pysis Jan 27 '22 at 17:04