cpio 无法提取文件

cpio 无法提取文件

在以下命令序列中,为什么cpio无法提取先前存档的文件?

/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

这里的问题是您使用了-depth中的选项find。这告诉find我们在目录本身之前处理目录内容。

正如您在输出中看到的find . -depth -print | cpio -ov > backup.cpio

  • ./eBooks/logstash_atlantis/03_output.conf在目录之前处理./eBooks/logstash_atlantis
  • ./eBooks/Container-Networking-Docker-Kubernetes.pdf之前已处理./eBooks
  • ...

当您尝试提取存档时,子目录中的所有文件都会失败,因为这些目录尚不存在(“无法打开:没有这样的文件或目录”)。

它也失败./backup.cpio,因为它已经存在于该目录中。

解决方案:不要将-depth的选项find与 结合使用cpio

相关内容