Linux / Unix Rsync Copy Hidden Dot Files and Directories Only

Linux / Unix Rsync Copy Hidden Dot Files and Directories Only

To copy hidden dot files and directories only with rsync in Linux or Unix, you can use the --include option followed by a pattern that matches the hidden dot files and directories, and the --exclude option followed by a pattern that excludes all other files and directories.

For example, to copy all hidden dot files and directories from the source directory /path/to/source to the destination directory /path/to/destination, you can use the following command:

rsync -av --include='/\.*/' --exclude='*' /path/to/source/ /path/to/destination/
Sou‮www:ecr‬.lautturi.com

This command will copy all hidden dot files and directories from the /path/to/source directory to the /path/to/destination directory. The -a option enables archive mode, which preserves the file permissions, ownership, and other attributes, and the -v option enables verbose output, which displays the names of the files being transferred.

The --include='/\.*/' option specifies a pattern that matches all hidden dot files and directories, and the --exclude='*' option specifies a pattern that excludes all other files and directories. The rsync command processes the --include and --exclude options in the order they are specified, so the --exclude='*' option is applied after the --include='/\.*/' option, effectively excluding all files and directories that do not match the pattern specified in the --include option.

Keep in mind that the rsync command does not follow symbolic links by default. If you want to copy the symbolic links themselves, rather than the files or directories they point to, you can use the --copy-links option.

For example:

rsync -av --copy-links --include='/\.*/' --exclude='*' /path/to/source/ /path/to/destination/

This command will copy all hidden dot files and directories, including symbolic links, from the /path/to/source directory to the /path/to/destination directory.

There are many other options and arguments that you can use with the rsync command to fine-tune the behavior of the transfer. For a complete list of options and more detailed information about how to use the rsync command, you can consult the rsync man page by running the man rsync command.

Created Time:2017-10-29 22:08:57  Author:lautturi