87

I have my Documents folder synced with iCloud drive, I want to exclude some sub folders from the iCloud drive is there a way to achieve this?

10 Answers 10

77

Update 2022

This method doesn't work anymore. you need to change the directory name to *.nosync, as described in other answers.


Adding one empty file named .nosync to a folder will prevent that folder from syncing.

You can also use this as a file extension to specific files, but the folder treatment is quite useful.

Once you've had a folder sync, you can now also prevent it from syncing on some (or all endpoints) with a utility named Bailiff, if for some reason you don't want just to delete the files from iCloud entirely and instead want to prevent the next "initial" sync.

11
  • 8
    what if you put a hidden .nosync file in the folder will that also stop the folder from syncing?
    – malhal
    Commented Aug 19, 2017 at 17:03
  • 2
    I want to avoid syncing a "build" folder too. In that case, I cannot change the name of that folder.
    – John Pang
    Commented Jan 7, 2018 at 9:31
  • 5
    This is not really accurate. The directory continues to sync up when a .nosync file is added; additionally, iCloud even seems to behave like the contents of the directory are uploading, and may even take up space, though I don't want to risk losing space that will never return, as I've seen many reports of space never de-allocating. The directory will show up in iCloud, though appears empty. In Finder, the .nosync file will be deemed "inelligible," but all the other files are considered "Downloaded." This is is disconcerting. Compare: i.imgur.com/uYybYAK.png Commented Jul 9, 2018 at 17:12
  • 4
    This didn’t work for me. I created an empty file called .nosync in the folder but everything else in the folder still synced. I created some new files in the folder and they were uploaded to iCloud Drive. I’m using Mojave.
    – Nate
    Commented Nov 8, 2018 at 5:11
  • 2
    2019-07-12 - this no longer seems to work. I have tried it on High Sierra (10.13.6) and Mojave (10.14.5) and even with .nosync files on each Mac, new content continues to sync. A sub-folder named "test.nosync" does not sync, nor do files which end with .nosync. But that's obviously less than ideal.
    – TJ Luoma
    Commented Jul 12, 2019 at 19:38
57

Here are all the file/folder names excluded so maybe one of these could be used for a workaround:

Filename:

  • is .DS_Store
  • begins with (A Document Being Saved
  • contains .nosync (in any case)
  • is .ubd
  • contains .weakpkg
  • is tmp (in any case)
  • is .tmp (in any case)
  • is desktop.ini (in any case)
  • begins with ~$
  • is Microsoft User Data (in any case)
  • is $RECYCLE.BIN (in any case)
  • is iPhoto Library (in any case)
  • is Dropbox (in any case)
  • is OneDrive (in any case)
  • is IDrive-Sync (in any case)
  • is .dropbox (in any case)
  • is .dropbox.attr (in any case)
  • is icon\r (in any case)

Extension is (in any case):

  • tmp
  • photoslibrary
  • photolibrary
  • aplibrary
  • migratedaplibrary
  • migratedphotolibrary
  • migratedaperturelibrary

Extension is more than 2 chars and filename is ~

Source: reversing iCloud daemon.

Hopefully in a future version of the OS they let us put .nosync inside the folder to exclude it, or have an .IgnoreList like Resilio has.

3
  • 3
    That's helpful, but can you please also add a source to your answer?
    – mklement0
    Commented Jan 9, 2018 at 13:12
  • 2
    iCloud Drive also excludes symlinks ("aliases").
    – twhb
    Commented Jul 9, 2018 at 20:09
  • Can anyone help me with the same for windows? Excluding a file from syncing with .nosync works, but this does not work for folders... they continue to sync normally. Commented Jun 23, 2021 at 13:28
24

Rename the folder or file:

mv fileorfolder fileorfolder.nosync

Create a symlink that get's synced:

ln -s fileorfolder.nosync fileorfolder

Repeat on every machine.

5
  • Nice one! Works with Magento 2.3.2, excluding paths 'var/cache', 'var/session', 'var/view_preprocessed/pub/static', 'pub/media/catalog/product/cache', 'pub/static' gonna save a lot of battery life!
    – Matt Rek
    Commented Dec 2, 2019 at 19:02
  • this worked for me. Also mentioned here 😊
    – Foad
    Commented Mar 25, 2020 at 10:44
  • 2
    Brilliant!!! And if you have node/npm you can add this as a single command with github.com/HaoChuan9421/nosync-icloud
    – user97042
    Commented Jan 23, 2021 at 3:54
  • 1/2: This (extremely useful) hint still works only a slight asterisk: When I used this approach on two Macs with Big Sur, the symbolic link I created on the first Mac was synced via iCloud to the second Mac, and it was pointing to exactly the same path as on my first Mac. On the second Mac, I had deleted the config file I was using this workflow for, so when I opened the app, it created a new someConfig.nosync file, just like I had set it up on my first Mac.
    – NSSynapse
    Commented Feb 15, 2022 at 9:28
  • 2/2: Long story short, it looks like the "Repeat on every machine" part no longer works/applies, because at least currently, the symbolic link is synced via iCloud so running the ln -s command on a second Mac would either fail or overwrite the existing symbolic link.
    – NSSynapse
    Commented Feb 15, 2022 at 9:28
12

Adding the .nosync file to the directory is not working anymore.

The directory has to be renamed to contain .nosync. Moreover, according to this thread on Reddit, it should be possible to chain the words like my_file.nosync.noindex to not only mark file as not-to-sync but also to hide it from Spotlight.

1
  • I confirm, it's not working anymore
    – sonique
    Commented Jun 18, 2021 at 23:40
10

Node developers: To add an empty file named .nosync to every node_modules subfolder, run this shell script from a parent directory:

find . -name node_modules -exec touch {}/.nosync \;
3
  • 2
    Very useful, thank you! I did combine it with -prune though, so that only those node_modules folders that were not themselves a sub-folder of another node_modules were targeted, which I discovered here: unix.stackexchange.com/a/582634
    – shuckster
    Commented Apr 12, 2021 at 9:25
  • this worked for you? definitely not working for me today.. ;( Commented Nov 23, 2021 at 13:01
  • You are correct, Someone Special, this no longer prevents syncing, as documented in many other comments on this page. The best solution might be from Appyx now. You could probably combine my idea with that one to automate it....
    – Jon Wilson
    Commented Nov 23, 2021 at 18:39
4

I created this Automator workflow to do it from the context menu in Finder https://github.com/tsdexter/iCloud-NoSync

3

It looks like directories that are named "tmp" or end with ".tmp" are not synced. A cloud icon with a line through it appears next to the directory along with anything inside of it.

0

The answer that worked for me really well was added as a comment above (https://apple.stackexchange.com/a/335629/117233), but for the sake of being thorough, I thought to add the actual code.

The way it worked for me was the following:

  1. Delete the folder you don't want to sync (or rename it if the content isn't auto-generated, e.g. node_modules)
  2. run the following in the parent directory of the above:
mkdir NAME_OF_FOLDER.nosync && ln -s NAME_OF_FOLDER.nosync NAME_OF_FOLDER

Then copy your content to the NAME_OF_FOLDER.nosync folder.

Hope it helps.

1
  • let's assume you have a react/angular project that you are working on which is located under the documents folder, now you want to sync everything except the node_modules folder. how to achieve that.? Will react/angular recognise 'node_modules.nosync'.?
    – Pradeep
    Commented Sep 17, 2022 at 0:39
0

You can, if you want to say exclude node_modules, make a dir/node_modules in an unsynced folder, move the files there, then create a symlink to that folder where the original node modules were. All code will run the same except iCloud sync which excludes symlinks.

.nosync doesn't work for this because node_modules must be called node_modules and should also not ever be synced.

-3

I just create folders directly under my user home that I want to keep only locally (separate from my iCloud folders).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .