简体   繁体   中英

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:

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. On the source:

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

This makes a file listing all directories (with trailing slashes thanks to ls -F ) and files.

On the destination:

./makestuff < stuff

Where makestuff is this script:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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