0

In the following sequence of commands, why does cpio fails to extract the files previously archived?

/home/pkara/Desktop/temp
$ ls
eBooks  myfile.tar
/home/pkara/Desktop/temp
$ find . -depth -print | cpio -ov > backup.cpio
./backup.cpio
./myfile.tar
./eBooks/logstash_atlantis/03_output.conf
./eBooks/logstash_atlantis/02_01_filter_paloalto.conf
./eBooks/logstash_atlantis/02_02_filter_squid.conf
./eBooks/logstash_atlantis/02_99_metrics_filter.conf
./eBooks/logstash_atlantis/01_input.conf
./eBooks/logstash_atlantis
./eBooks/Container-Networking-Docker-Kubernetes.pdf
./eBooks/lpic-1_2013.pdf
./eBooks/linux-bible-by-christopher-negus.pdf
./eBooks/PythonNotesForProfessionals.pdf
./eBooks/lpic1-notes
./eBooks
.
129731 blocks
/home/pkara/Desktop/temp
$ mkdir -p foo
/home/pkara/Desktop/temp
$ mv backup.cpio foo && cd $_
/home/pkara/Desktop/temp/foo
$ cpio -iv < backup.cpio 
cpio: backup.cpio not created: newer or same age version exists
backup.cpio
myfile.tar
cpio: eBooks/logstash_atlantis/03_output.conf: Cannot open: No such file or directory
eBooks/logstash_atlantis/03_output.conf
cpio: eBooks/logstash_atlantis/02_01_filter_paloalto.conf: Cannot open: No such file or directory
eBooks/logstash_atlantis/02_01_filter_paloalto.conf
cpio: eBooks/logstash_atlantis/02_02_filter_squid.conf: Cannot open: No such file or directory
eBooks/logstash_atlantis/02_02_filter_squid.conf
cpio: eBooks/logstash_atlantis/02_99_metrics_filter.conf: Cannot open: No such file or directory
eBooks/logstash_atlantis/02_99_metrics_filter.conf
cpio: eBooks/logstash_atlantis/01_input.conf: Cannot open: No such file or directory
eBooks/logstash_atlantis/01_input.conf
cpio: eBooks/logstash_atlantis: Cannot mkdir: No such file or directory
eBooks/logstash_atlantis
cpio: eBooks/Container-Networking-Docker-Kubernetes.pdf: Cannot open: No such file or directory
eBooks/Container-Networking-Docker-Kubernetes.pdf
cpio: eBooks/lpic-1_2013.pdf: Cannot open: No such file or directory
eBooks/lpic-1_2013.pdf
cpio: eBooks/linux-bible-by-christopher-negus.pdf: Cannot open: No such file or directory
eBooks/linux-bible-by-christopher-negus.pdf
cpio: eBooks/PythonNotesForProfessionals.pdf: Cannot open: No such file or directory
eBooks/PythonNotesForProfessionals.pdf
cpio: eBooks/lpic1-notes: Cannot open: No such file or directory
eBooks/lpic1-notes
eBooks
.
129731 blocks

1 Answer 1

1

The problem here is that you use the -depth option in find. This tells find to process the directory contents before the directory itself.

As you can see in the output of find . -depth -print | cpio -ov > backup.cpio:

  • ./eBooks/logstash_atlantis/03_output.conf is processed before the directory ./eBooks/logstash_atlantis
  • ./eBooks/Container-Networking-Docker-Kubernetes.pdf is processed before ./eBooks.
  • ...

When you try to extract the archive it fails for all files in subdirectories, because the directories don't exist yet ("Cannot open: No such file or directory").

It also fails for ./backup.cpio, because it already exists in this directory.

Solution: Don't use the -depth option of find in combination with cpio.

2
  • This works and I have accepted your answer, however if for example if I name my file archive.cpio, during extraction I get: cpio: archive.cpio not created: newer or same age version exists
    – pkaramol
    Apr 18, 2019 at 11:32
  • 1
    @pkaramol Your archive exists in the directory and in the archive itself, because it was created in the same directory as the files. You can (1) exclude the archive from find with find . ! -name *.cpio -print | cpio -ov > archive.cpio or (2) create the archive in a different directory: find . -print | cpio -ov > /tmp/archive.cpio
    – Freddy
    Apr 18, 2019 at 11:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .