-1

How copy files from file-name list and unconditional keep existing file in destination?

Note cpio is overwrite older existing files by default:

$ dpkg -L libgcc1 libstdc++6 |grep -e '^/lib/' -e '^/usr/lib/' |  cpio -pdv ./test
./test/lib/i386-linux-gnu
cpio: ./test/lib/i386-linux-gnu/libgcc_s.so.1 not created: newer or same age version exists
./test/usr/lib/i386-linux-gnu
cpio: ./test/usr/lib/i386-linux-gnu/libstdc++.so.6.0.22 not created: newer or same age version exists
cpio: ./test/usr/lib/i386-linux-gnu/libstdc++.so.6 not created: newer or same age version exists
0 blocks
$ touch -ht 200102030405 $(find  . )
$ dpkg -L libgcc1 libstdc++6 |grep -e '^/lib/' -e '^/usr/lib/' |  cpio -pdv ./test
./test/lib/i386-linux-gnu
./test/lib/i386-linux-gnu/libgcc_s.so.1
./test/usr/lib/i386-linux-gnu
./test/usr/lib/i386-linux-gnu/libstdc++.so.6.0.22
./test/usr/lib/i386-linux-gnu/libstdc++.so.6
3222 blocks
$ #same version
$ dpkg -L libgcc1 libstdc++6 |grep -e '^/lib/' -e '^/usr/lib/' |  cpio -pdv ./test
./test/lib/i386-linux-gnu
cpio: ./test/lib/i386-linux-gnu/libgcc_s.so.1 not created: newer or same age version exists
./test/usr/lib/i386-linux-gnu
cpio: ./test/usr/lib/i386-linux-gnu/libstdc++.so.6.0.22 not created: newer or same age version exists
cpio: ./test/usr/lib/i386-linux-gnu/libstdc++.so.6 not created: newer or same age version exists
0 blocks
$ cp --version
cp (GNU coreutils) 8.26
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Torbjorn Granlund, David MacKenzie, and Jim Meyering.
$ 
  • cpio shouldn't overwrite files unless instructed to. – Raman Sailopal Aug 30 '18 at 12:15
  • I'm tested for this ,see my update .@RamanSailopal – illiterate Aug 30 '18 at 12:27
  • There is no way to do this with cpio. – schily Aug 30 '18 at 12:30
0

There is no way to do this with cpio.

You however may use star to do the job. Just call:

star -xpk < archive-name

BTW: I am not sure whether GNU cpio behaves correectly but cpio is often used in system management because it has an undocumented feature to extract files first into a temporary name and if this succeeded, to call rename(2) to replace the old file in a non-destuctive way. So the official cpio (not necessarily GNU cpio) behaves like the install program.

If you like to get this behavior with star, add the -install option.

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.