Hacker News new | comments | show | ask | jobs | submit login

cp most certainly does copy directory structures. Just not filtered ones whereby just certain entries are arbitrarily selected from the source tree and only those are replicated in the destination tree.

The issue in the question is that the person has expanded, into the cp command line, a bunch of full paths, effectively like "cp a/b/c/file1 a/b/d/file2 .... dest" and wants those relative paths to be re-created under dest as dest/a/b/c/file1 and so on. Indeed, cp does not do that; it simply puts the specified objects file1 file2 ... into dest.

An option to create each object's relative path under dest would be useful, but it would be a pretty awful default behavior.

GNU cp has this option:

  `--parents'
     Form the name of each destination file by appending to the target
     directory a slash and the specified name of the source file.  The
     last argument given to `cp' must be the name of an existing
     directory.  For example, the command:

          cp --parents a/b/c existing_dir

     copies the file `a/b/c' to `existing_dir/a/b/c', creating any
     missing intermediate directories.
GNU Coreutils is in active development, unlike the Windows command line which is basically abandonware (as, to be even-handed, is the Unix (tm) command line.)



Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: