Archive

cpio 無法提取文件

  • April 18, 2019

在以下命令序列中,為什麼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

這裡的問題是您-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

引用自:https://unix.stackexchange.com/questions/513176