1

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??

Siddharth Trikha
  • 2,648
  • 8
  • 57
  • 101

1 Answers1

1

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
John Zwinck
  • 239,568
  • 38
  • 324
  • 436