Unix & Linux Asked by Alexander Mills on January 25, 2021
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?
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"/* ...
Correct answer by Hauke Laging on January 25, 2021
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/
Answered by 16851556 on January 25, 2021
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.
Answered by wurtel on January 25, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP