This is a cheat-sheet for the rsync
syntax with examples for different use-cases I needed in the past. It is not meant as a full tutorial about rsync
.
Copy Directory
To copy the content from dir-a to dir-b you can use rsync like that.
[tux@server]$ rsync -av source destination
Exclude
Exclude single file or directory
If you only want to exclude a single file or directory, you can use the parameter exclude
.
[tux@server]$ rsync -a --exclude="path/to/exclude" source destination
Exclude List
You can use an exclude list with rsync
. Just create a file and add one entry per line.
exclude-list.txt
*/node-modules/*
secret-file.txt
path/to/a/nested/file.pdf
When running the rsync
command, you need to include the list with the exclude-from
Parameter.
[tux@server]$ rsync -a --exclude-from="path/to/exclude-list.txt" source destination
Delete additional files
If you set the --delete
flag rsync
will delete files in the destination, that are not present in the source.
[tux@server]$ rsync -av --delete source destination
Progress
Set the --progress
flag to get an progress-indication. This is more useful for larger files, since the progress is on a per-file-basis. If you have lots of small files, you will only clutter up your output.
[tux@server]$ rsync -av --progress source destination
Synchronize two Directories
If you combine the copy and delete function, you can sync two directories.
[tux@server]$ rsync -av --delete --progress source destination
Other Parameters
Preserve Permissions
-p
Preserve Owner
-o
Preserve Group
-g