1

I'm using the following command to make a full, recursive copy of the contents of one directory into another :

rsync -avzhe /path1/to1/dir1/* /path2/to2/dir2/

It works as I expect it to, except that the first file (in alphabetical order), be it a directory or a file, is not copied. Every other file gets copied. Why ?

My OS is MacOS 10.14.6 if that matters.

9

The -e option needs an argument, so it takes the first filename for that. I'm not sure why you want -e as it sets the command to use to connect to the remote, but you are not using a remote. Just remove the -e.

1
  • Thanks. I used that command in a remote situation a long time ago, and unthinkingly reused it as is. Oct 21 at 9:21
6

To make a full copy of the directory /path1/to1/dir1 called /path2/to2/dir2, use

rsync -av /path2/to1/dir1/ /path2/to2/dir2

There is no point in using compression (-z) for a local copy. The -e option specifies the command used to establish the network connection (which is why your command fails in copying the first file; rsync uses it as the option-argument to the -e option), so that should be removed too in this scenario.

Also, don't use * at the end of the source path, as that would ordinarily not match any hidden names. Globbing all names under dir1 could potentially also expand to a list too long for the command to execute at all.

Just make sure that the source path ends with a slash. A slash at the end of the destination path makes no difference. Removing the slash from the source path would copy dir1 inside dir2. A slash at the end of the source path makes dir2 a copy of dir1.

Other than that, you may want to use -H to make sure hard links are established correctly at the destination and --sparse if you know you are copying files that may be sparse (like pre-allocated disk images).

Use --delete to also delete entries from the destination that is not part of the source file hierarchy. Use this with caution. You may want to test run with -n (--dry-run) first.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.