Here are some examples of how to exclude stuff with
I hope this post helps you to exclude what exactly you want and nothing more and nothing
less without going mental. A few
rsync calls are shown below, which are
copy from the source directory
src into a target directory
The source directory looks like this:
src: ├── dir1 │ └── dir11 │ ├── file1 │ └── file2 ├── dir2 │ ├── dir1 │ └── dir21 ├── file1 └── file2
The directory views in this post were created with the command line tool
rsync -a --exclude '/dir1' src/ dst creates the following in the target directory:
dst: ├── dir2 │ ├── dir1 │ └── dir21 ├── file1 └── file2
dir1 in the working directory was omitted.
/ dir2 / dir1 is still there.
/ at the beginning of
/dir1 leads to that of the current directory
rsync always starts from the current working directory.
--exclude '/dir1' does not cause folders or files
dir1 from subdirectories are ignored.
Furthermore, it does not mean that the root directory
/ of the system is searched.
/ to the source directory
src means that only the content of
the source directory is copied, not the directory itself.
So it makes a difference whether you call
rsync -a src dst or
rsync -a src/ dst.
Here is the target directory if
/ is omitted. Executing
rsync -a --exclude 'dir1' src/ dst results in:
dst: ├── dir2 │ └── dir21 ├── file1 └── file2
dir1 is missing in both, the working and subdirectories.
Include folder, exclude content
Folders can be synchronized using
--exclude '/dir1/*'. Their content will
be excluded. Executing
rsync -a --exclude 'dir1/*' src/ dst leads to:
dst: ├── dir1 ├── dir2 │ ├── dir1 │ └── dir21 ├── file1 └── file2
Exclude files or folders
Like folders, files are of course excluded from the patterns specified with
--exclude 'file*' excludes files and folders starting with
rsync -a --exclude 'file*' src/ dst results in:
dst: ├── dir1 │ └── dir11 └── dir2 ├── dir1 └── dir21
--exclude 'file*/' would only exclude folders beginning with the string
Exclude multiple patterns
--exclude can also be applied several times:
rsync -a --exclude '/dir1' --exclude '/dir2' src/ dst
Exclude a lot
If you have a lot to exclude, you can use the parameter
In this example you can use the file
exclude-list.txt holding the exclude patterns
you desire. Each exclude pattern is to be specified in a separate line.
Comments can be started with
Example of an
/dir1 /dir2/* file1
A good exclude list for linux home directories can be found here.