Skip to content

Instantly share code, notes, and snippets.

@peterdemartini
Last active May 27, 2026 09:51
Show Gist options
  • Select an option

  • Save peterdemartini/4c918635208943e7a042ff5ffa789fc1 to your computer and use it in GitHub Desktop.

Select an option

Save peterdemartini/4c918635208943e7a042ff5ffa789fc1 to your computer and use it in GitHub Desktop.
Exclude node_modules in timemachine
find `pwd` -type d -maxdepth 3 -name 'node_modules' | xargs -n 1 tmutil addexclusion
@dj1020

dj1020 commented Jun 6, 2023

Copy link
Copy Markdown

Trying to use fd to replace find

fd -t d -d 5 -a --no-ignore --prune node_modules | xargs -I {} tmutil addexclusion {}

@n8henrie

n8henrie commented Dec 14, 2023

Copy link
Copy Markdown

This thread shows up fairly high in my searches for excluding python virtualenvs from timemachine.

Just wanted to point out for folks looking to dig a little deeper that there is some good info out there on the xattr that's being set on the item leading to exclusion, including faster ways to find these files (with mdfind -- though this will skip files that are not indexed by spotlight) and likely some other opportunities to set the attribute directly with xattr if desired:

@n8henrie

n8henrie commented Dec 14, 2023

Copy link
Copy Markdown

Also, it appears that tmutil addexclusion supports multiple args:

$ mkdir -p {foo,bar}
$ ls
bar  foo
$ xattr *
$
$ tmutil addexclusion ./foo ./bar
$ xattr *
bar: com.apple.metadata:com_apple_backup_excludeItem
foo: com.apple.metadata:com_apple_backup_excludeItem

which means that many of the above commands could probably be done much more efficiently with find ... -exec tmutil addexclusion {} +, which collects arguments and runs the command once with collected arguments, as opposed to \; or piping to xargs / parallel, which will be separate invocations of tmutil.

EDIT: The equivalent for fd is --exec-batch

@kepoorz

kepoorz commented Jul 31, 2025

Copy link
Copy Markdown

i was searching for a solution and this helped me a lot so im gonna drop a little here.

for fish and showing logs for what you're adding

find . -type d -maxdepth 3 -name 'node_modules' | while read -l line
     echo "Excluding: $line"
     tmutil addexclusion "$line"
end

and to check what you added

find . -type d -maxdepth 3 -name 'node_modules' | while read -l line
    tmutil isexcluded "$line"
end

@tinny77

tinny77 commented Apr 8, 2026

Copy link
Copy Markdown

This works for me

mdfind "kMDItemFSName == 'node_modules'" > /tmp/node_modules_paths.txt && sudo /bin/zsh -c 'while IFS= read -r p; do [ -d "$p" ] && tmutil addexclusion -p "$p"; done < /tmp/node_modules_paths.txt'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment