I’ve searched all over the internet and everybody suggests the same thing - that adding --exclude=´.*´ should exclude hidden files and folders from an rsync. It doesn’t. I´ve also tried adding a slash and/or double quotes eg. --exclude=¨\.*¨ Nothing seems to work. AGH!! Would really appreciate some help.
- 887
- 2
- 9
- 13
5 Answers
Both versions you are showing are wrong. You need to use double quotes. The following works and excludes hidden files and directories:
--exclude=".*"
If you only want to exclude hidden directories:
--exclude=".*/"
- 12,964
- 10
- 49
- 77
- 293,910
- 41
- 570
- 710
I use this expression: --exclude=".[!.]*"
Does the job well for me excluding hidden files and directories.
- 9,995
- 2
- 78
- 90
- 183
- 1
- 4
Open a text file exclude_me.txt and type the following: .[a-z]*
Then execute the following:
rsync -avh --exclude-from='exclude_me.txt' /path/of/Source /path/of/Destination
-
1This article explains it in detail (may be useful): https://www.howtogeek.com/168009/how-to-exclude-files-from-rsync/ – Levente Jan 25 '21 at 12:51
--exclude="/.*" your \ is pointing the wrong way .
rsync -a --exclude="/.*" ./ /path/to/sync
-
2There is no need for the / :) he is not using "'s. If he needed a / is should be at the end to exclude dirs. – Rinzwind Jun 13 '14 at 19:01
This is the rsync command I use to make a copy of my local Dropbox folder, from my MacBook (MacOS) to an external network drive (mounted as extdisk below).
rsync -atv --delete --delete-excluded --exclude "DontCopyThisFolder" --exclude=".*" "/Users/admin/Dropbox/" "/Volumes/extdisk/Files/Dropbox/"
It uses the options:
- archive
- perserve times (on files & folders)
- verbose progress output (to see what is going on)
- delete and delete-excluded will remove all files from the destination that are not included in the list of files to copy. This also removes files that might have been copied by other means, but now isn't, because of the exclude "DontCopyThisFolder"-option, or the exclude=".*"-option that will exclude files starting with a dot.
Further documentation and options can be found at the rsync Man Page
- 101
- 3
-
The version of `rsync` that comes with Mac OS has a strange quirk: If you use the `-E` option it doesn't allow you to exclude dotfiles. So `exclude=".*"` or `exclude="._*"` have no effect in combination with `-E` . – asmaier Sep 06 '22 at 20:27