C.W.K.
Stream
Lesson 06 of 12 · published

Excluding Files

~12 min · rsync, exclude, rsyncignore

Level 0Pinger
0 XP0/101 lessons0/12 achievements
0/150 XP to next level150 XP to go0% complete

Skip the cruft

You almost never want to sync a project verbatim. node_modules, .git, build artifacts, .DS_Store, __pycache__, log files — all noise. Excluding them speeds transfers, saves space, and avoids overwriting target-side state you didn't mean to touch.

Two ways: inline and .rsyncignore-style

For one-offs, inline --exclude per pattern. For project work, keep the patterns in a file and use --exclude-from=. Same syntax as gitignore-ish: leading / anchors to the source root, trailing / matches directories, * globs.

Code

Inline excludes·bash
rsync -avz \
  --exclude '.git' \
  --exclude 'node_modules' \
  --exclude '*.log' \
  --exclude '.DS_Store' \
  --exclude '__pycache__' \
  --exclude '.venv' \
  ./project/ host:/dest/
From a file (the tidy way)·bash
# .rsyncignore at the source root
cat > .rsyncignore <<'EOF'
.git
node_modules
.next
dist
build
*.log
.DS_Store
.env
__pycache__
*.pyc
.venv
.pytest_cache
EOF

# Use it
rsync -avz --exclude-from='.rsyncignore' ./project/ host:/dest/

External links

Exercise

Take a real project. Without excludes: rsync -avzn ./project/ host:/tmp/x/ | wc -l — count the files rsync would touch. Now with --exclude '.git' --exclude 'node_modules' — note the new count. The difference is bandwidth and time you'd otherwise waste every sync.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.