Linux / Unix Rsync Copy Hidden Dot Files and Directories Only

Tutorial details Difficulty Easy (rss) Root privileges No Requirements rsync / bash or ksh Time 2m

ls -ld ~/.??*

ls -ld ~/.[^.]*

ADVERTISEMENTS



rsync not synchronizing all hidden .dot files?

How do I use the rsync tool to copy only the hidden files and directory (such as ~/.ssh/, ~/.foo, and so on) from /home/jobs directory to the /mnt/usb directory under Unix like operating system?The rsync program is used for synchronizing files over a network or local disks. To view or display only hidden files with ls command:ORSample outputs:

In this example, you used the pattern .[^.]* or .??* to select and display only hidden files using ls command. You can use the same pattern with any Unix command including rsync command. The syntax is as follows to copy hidden files with rsync:

rsync -av / path / to / dir / .?? * / path / to / dest rsync -avzP / path / to / dir / .?? * / mnt / usb rsync -avzP $HOME / .?? * user1 @ server1.cyberciti.biz: / path / to / backup / users / u / user1 rsync -avzP ~ / . [ ^. ] * user1 @ server1.cyberciti.biz: / path / to / backup / users / u / user1 rsync -av /path/to/dir/.??* /path/to/dest rsync -avzP /path/to/dir/.??* /mnt/usb rsync -avzP $HOME/.??* user1@server1.cyberciti.biz:/path/to/backup/users/u/user1 rsync -avzP ~/.[^.]* user1@server1.cyberciti.biz:/path/to/backup/users/u/user1

In this example, copy all hidden files from my home directory to /mnt/test:

rsync -avzP ~ / . [ ^. ] * / mnt / test rsync -avzP ~/.[^.]* /mnt/test

Sample outputs:



Rsync Copy Hidden Dot File Command Options

The options are as follows:

-a – Archive mode copy. In this mode all given files are copied in recursive mode. Copy symlinks as symlinks, file permissions, date and time stapms, and much more. -v – Verbose copy. In other words, show what the rsync is doing. -z – Compress file data during the transfer. -P – Display progress bar

Conclusion

You learned how to to use the rsync command to copy hidden dot files including directories. See rsync man page here for more info or type the following man command:

man rsync