how to migrate the hidden files using rsync

I am using the command below, in my target sever:

rsync -ab myuser@sourcehost:/source_dir/* target_dir

But this is not able to sync the hidden files present source_dir anything I need to use any --include so that the hidden files can be migrated.

But that include option should not affect the migration of normal files as I'm using this command in my script.

What should I do?

0

1 Answer

The problem is not rsync, but the shell.

Normally in Ubuntu, dotglob is disabled, meaning that files starting with . are excluded from * expansion.

You can turn this on running.

shopt -s dotglob

Then your command should work (I think you're just missing -e ssh)

It's sensible to unset dotglob after use with:

shopt -u dotglob

Alternatively, you can simply tell rsync to copy the folder contents to target_dir, which includes hidden files:

rsync --ab -e ssh myuser@sourcehost:/source_dir/ target_dir

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like