Filter Files With rsync Include and Exclude
Sync only matching files while still traversing directories.
Use --include='*/' then --include='*.md' then --exclude='*' to copy only Markdown files.
01Command
Command
$ rsync -av --include='*/' --include='*.md' --exclude='*' docs/ backup/02What it does
rsync applies filter rules in order, so including directories first keeps traversal while the final exclude drops everything else. This makes targeted backups and content syncs fast and reproducible, and the same rules can be stored in a file for reuse.
03Risk
!Warning: Rule order is significant: a broad exclude before an include prevents the include from ever matching.
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- rsync.1.en.html manual page (Debian bookworm)Evidence: Documents include/exclude filter rules and their precedence.
Last verified: 2026-10-13 · Category: Files & Folders
06Related solutions
Search text recursively in a directory with grep
Find every occurrence of a pattern across all files in a tree, printed as file:line:number matches.
Extract a .tar.gz archive with tar
Unpack a gzipped tarball into the current directory while printing each file as it is extracted.
Copy and Sync Files with rsync
rsync copies over SSH, skips unchanged files, resumes interrupted transfers, and preserves permissions and timestamps.