9

Reason is I want to make a tidy script instead of

cd /some/dir
cpio -whatever<somefile
cd -
HopelessN00b
  • 53,795
  • 33
  • 135
  • 209
Erik I
  • 483
  • 3
  • 7
  • 18

3 Answers3

10

There is nothing in GNU cpio to allow for this. This might be a little cleaner:

(cd /some/dir && cpio -whatever < /some/file)

Using the subshell parentheses will preserve the scripts current working directory and using && will ensure that the cpio extraction is only done if you successfully change directories to the target.

TCampbell
  • 2,024
  • 14
  • 14
  • 3
    The `somefile` has to actually reside in `/some/dir` here. I just tried it and it sayd it couldn't find the files. So you either have to use relative paths back to where the files were or absolute paths. – CMCDragonkai Feb 13 '16 at 11:28
0

Use -D option (cpio (GNU cpio) 2.13, should be available in most modern distributions):

OPTIONS
   Operation modifiers valid in any mode
       -D, --directory=DIR
              Change to directory DIR.
cat archive | cpio -D /tmp/outdir -idmv

Output directory will be created, if it doesn't exist.

0

Adding a little more to what TCampbell did:

(cp /some/file /some/dir && cd /some/dir && cpio -whatever < file && rm -f file)

Payero
  • 1