5

I have the following command:

rsync -r --exclude="node_modules" "/r2g_shared_dir/vamoot"/* "/home/node/.docker_r2g_cache/b640e7fd-27a7-4dd8-8ca8-5363a1c59c35"

I just realized that using /* will not copy over dot files (files/folders that start with .)...

Anybody know how I can include those files?

I assume the best way would be to forgo the /* notation and just use

rsync -r --exclude="node_modules" "/r2g_shared_dir/vamoot" "/home/node/.docker_r2g_cache/b640e7fd-27a7-4dd8-8ca8-5363a1c59c35"

but is there another way?

3 Answers 3

6

It's best to leave the pattern matching to rsync, then you're not depending on whatever shell and options that shell has at that time.

When you do:

rsync -a /some/dir/* host:/remote/dir/

then you're actually asking the shell to expand the /some/dir/* part, so that rsync is actually executed like this:

rsync -a /some/dir/adir /some/dir/afile /some/dir/anotherfile [etc] host:/remote/dir/

This is usually quite similar to what the intention was, however not always as demonstrated by the fact that this question was asked. Hence it's better to execute:

rsync -a /some/dir/ host:/remote/dir/

Now rsync will (because -a is shorthand for -rlptgoD which includes -r for recursion) recursively walk through the /some/dir directory and sync all its contents to /remote/dir on the remote host, including any dot files directly in /some/dir.

As the source path ends with a slash /, the filenames transferred omit any part of the source location. If /some/dir was passed, then you're telling to explicitly sync the dir directory, including its name. It's recommended to get into the habit of adding the last slash at all times to avoid such confusion, unless you really understand what's going on.

1

I think the best is to use archive mode (-a), manual pages says about it: "This is equivalent to -rlptgoD. It is a quick way of saying you want recursion and want to preserve almost everything (with -H being a notable omission).":

rsync -a /source/path/ /destination/path/
  • always use ending slash /
  • do not use * as it does not include dot files
  • if transferring over network that is slower than disk read/write, consider compression -z
0

If this is bash you can just set dotglob:

shopt -s dotglob

This does not match . or .. (in contrast to .*).

So the same command could be used:

rsync -r --exclude="node_modules" "/r2g_shared_dir/vamoot"/* ...
6
  • So I would do: rsync -r "/r2g_shared_dir/vamoot"/.* ?? Commented May 27, 2018 at 21:09
  • @AlexanderMills No, see the edit. Sorry, I thought that was obvious. Commented May 27, 2018 at 21:24
  • ah sorry now I get it Commented May 27, 2018 at 21:25
  • 1
    It would be better to simply leave out the * in the rsync command, but include the slash, otherwise the vamoot directory is also trasferred in the path: rsync -r "/r2g_shared_dir/vamoot"/ ....
    – wurtel
    Commented May 28, 2018 at 14:48
  • @wurtel It might be more useful to make that an answer. Commented May 28, 2018 at 17:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .