I know this question is old but it's what I found when I looked for guidance on this. Using the Dropbox feature How to set a Dropbox file or folder to be ignored
mentioned above by two responders, I wrote this one-liner to traverse my entire Dropbox and mark all .git
, node_modules
, and packages
folders to be ignored by Dropbox. Just change the parameters between the parentheses to whatever you want to be ignored. The -o
means "or" and has to be included between match patterns if you want more than one. Here's what I used on my machine:
find ~/Dropbox \( -name 'packages' -o -name 'node_modules' -o -name '.git' \) -print0 | xargs -0 xattr -w com.dropbox.ignored 1
This recurses through every folder in your dropbox (assuming it's at ~/Dropbox
, adjust if not) and uses xargs
to call xattr -w com.dropbox.ignored 1
on each result, as instructed on Dropbox's support page. To undo it, keep the find
command as-is and replace -w com.dropbox.ignored 1
with -d com.dropbox.ignored
, e.g.
find ~/Dropbox \( -name 'packages' -o -name 'node_modules' -o -name '.git' \) -print0 | xargs -0 xattr -d com.dropbox.ignored
Caveats:
- Works on 100% of the one machines I've tried it on (macOS Monterey)! Caveat emptor!
- If you add a new git project you'll need to run this again, as the script only marks the actual files/folders it finds to be ignored, it doesn't do anything for any future folders that would match the
find
statement.
- I don't imagine there's any harm in marking folders ignored multiple times but maybe there is? If so, that would be relevant for point #2 above.
I had 9.3GB worth of files in my Dropbox folder and after running this, Dropbox reports I am only using 5.1GB! Since my free account maxed out at 8.6GB (referral bonuses) this solved my out of space errors and gave me a huge margin of remaining space! Hope this helps others.
UPDATE 2022-08-08: This failed for me on a path containing spaces, since by default xargs views any whitespace as a delimiter. Based on this answer elsewhere I added -print0
and -0
in the commands above. -print0
tells find to use null as the delimiter instead of a newline and -0
tells xargs
to only use null as delimiter instead of all whitespace.