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

Only problem is, those commands are useless. COPY won't back up a directory tree. You need XCOPY. Oops, XCOPY chokes for weird reasons and terminates with a strange error message because a path was more than 255 bytes. It needs a bazillion options to do the equivalent of GNU's "cp -a". If you go online to get help with this, the best advice you get is to download and install something called RoboCopy.

Yes, MS-DOS was easy to learn. XCOPY worked in MS-DOS.


"copy doesn't copy directory structures, it will only copy the files, hence the error message you're encountering. To do a deep copy such as this you can enlist either the tar command and use the construct tar cvf - --files-from=... | (cd /home/tmp/test/files/; tar xvf -) or you can just use rsync."

That's so much better..

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:

     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