An rsync filter that is too broad can skip files that should be copied or transfer caches, logs, and temporary files that should stay local. Exclude rules let rsync build a smaller file list before the transfer starts, and a dry run shows the exact paths that would still move.
Rsync applies include and exclude rules in order while it scans the source tree. A directory pattern such as cache/ prevents traversal into that directory, while a filename pattern such as *.tmp matches temporary files at the scanned levels. Repeat --exclude for short rule lists, or move longer rule sets into --exclude-from so the command stays readable.
The examples below use a local project/ source tree and a backup/ destination so the filter effect is visible before any files are copied. Keep the trailing slash on project/ when the destination should receive the source directory contents, and review delete behavior separately because excluded files are normally protected from --delete unless --delete-excluded is used.
Steps to exclude files and folders with rsync:
Selective sync using rsync using include and exclude option
- Review the source tree and choose the paths that should stay out of the transfer.

- Preview the transfer with inline exclude rules.
$ rsync -a --dry-run --itemize-changes --exclude='cache/' --exclude='*.tmp' project/ backup/ created directory backup cd+++++++++ ./ >f+++++++++ README.md cd+++++++++ logs/ >f+++++++++ logs/app.log cd+++++++++ reports/ >f+++++++++ reports/summary.txt cd+++++++++ src/ >f+++++++++ src/app.py
The output includes reports/summary.txt and src/app.py, but it does not include cache/ or reports/draft.tmp.
- Verify that the dry-run output contains only files that should be copied before removing --dry-run from the command.
- Put include rules before the final catch-all exclude when the transfer should keep only one part of the source tree.
$ rsync -a --dry-run --itemize-changes --include='reports/***' --exclude='*' project/ backup/ created directory backup cd+++++++++ ./ cd+++++++++ reports/ >f+++++++++ reports/draft.tmp >f+++++++++ reports/summary.txt
Rsync stops at the first matching filter rule, so the include rule must appear before the final --exclude='*' rule.
Selective sync using rsync by specifying pattern file
- Create an exclude pattern file for rules that should be reused.
cache/ *.tmp
Blank lines and whole-line comments starting with # are ignored in --exclude-from files.
- Run the dry run with the pattern file.
$ rsync -a --dry-run --itemize-changes --exclude-from=exclude-rules.txt project/ backup/ created directory backup cd+++++++++ ./ >f+++++++++ README.md cd+++++++++ logs/ >f+++++++++ logs/app.log cd+++++++++ reports/ >f+++++++++ reports/summary.txt cd+++++++++ src/ >f+++++++++ src/app.py
- Add more patterns to the file when a later run exposes files that should be skipped.
Use How to debug rsync filter rules when a rule does not match the path you expected.
Explicitly specify files to be synced for rsync
- Create a source-file list when the transfer should copy only named paths instead of excluding everything else.
README.md reports/summary.txt src/app.py
--files-from is an allow-list. Each entry is relative to the source path, and rsync preserves the listed path structure by default.
- Preview the file-list transfer.
$ rsync -a --dry-run --itemize-changes --files-from=rsync-files.txt project/ backup/ created directory backup >f+++++++++ README.md cd+++++++++ reports/ >f+++++++++ reports/summary.txt cd+++++++++ src/ >f+++++++++ src/app.py
- Run the live sync only after the dry-run output contains the intended files and no skipped path is required by the destination.
When a mirror command also uses --delete, review delete behavior with the same filter rules before running it against an important destination.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.