How can I exclude files by default with rsync?
Add your excludes to a file, then use --exclude-from=/path/to/exclude_file
e.g.
# cat rsync.excludes
.ht*
error_log
.DS*
old
...
# rsync --exclude-from=rsync.excludes
No, rsync
does not have a default configuration file that it will read upon invocation. The best you can do is what @frogstarr78 says and create a text file with patterns, file and directory names to exclude, and then point rsync
to it with --exclude-from=filename
.
While rsync doesn't let you set default options, you can create a wrapper script and put it higher up in your $PATH than the rsync binary.
This is is my rsync wrapper which lives in ~/bin/rsync
#!/bin/sh
# Set path to the rsync binary
RSYNC=/usr/bin/rsync
# Look for these exclude files
IGNORE_FILES=(~/.rsyncignore ./.gitignore ./.rsyncignore)
EXCLUDE_FROM=""
for f in ${IGNORE_FILES[@]}; do
if [[ -e $f ]]; then
EXCLUDE_FROM="$EXCLUDE_FROM --exclude-from=$f "
fi
done
$RSYNC $EXCLUDE_FROM "$@"
It'll look for ~/.rsyncignore
, ./.gitignore
, ./.rsyncignore
files and, if any of them exist, use them as default --exclude-from
arguments.
Just change the RSYNC and IGNORE_FILES to suit your envrionment and preferences.