简体   繁体   English

linux cpio复制目录结构和文件名?

[英]linux cpio to copy directory structure and file names?

I want to copy a directory structure from a remote machine to a local machine. 我想将目录结构从远程计算机复制到本地计算机。 I want the file names too but not the content of the file. 我也想要文件名,但不需要文件的内容。

Presently I did this in the remote machine: 目前,我是在远程计算机上执行此操作的:

find . -type d -print | cpio -oO dirs.cpio

then copied the dirs.cpio file to local machine, and ran the command after going to directory where I want the structure replicated: 然后将dirs.cpio文件复制到本地计算机,并在要复制结构的目录后运行命令:

cpio -iI dirs.cpio

So this creates the directory structure I want including subdirectories, but does not copies the file names . 因此,这将创建我想要的包含子目录的目录结构,但不会复制文件名 I want the directory structure and file names but not their content. 我想要目录结构和文件名,而不是它们的内容。

How can I get the file names too?? 我也如何获得文件名?

It's easier without cpio. 没有cpio会更容易。 On the source: 在源上:

find . -exec ls -Fd {} + > stuff

This makes a file listing all directories (with trailing slashes thanks to ls -F ) and files. 这将使文件列出所有目录(由于ls -F带有斜杠)和文件。

On the destination: 在目的地:

./makestuff < stuff

Where makestuff is this script: 这个脚本的makestuff在哪里:

while read name; do
  if [ "${name:${#name}-1}" = "/" ]; then
    mkdir -p "$name"
  else
    touch "$name"
  fi
done

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM