Sub topic 14
Excluding folders with the .nosync suffix
This chapter assumes you can use Terminal and basic shell commands (cd, ls, mv). It also assumes you know where iCloud Drive lives on disk, which the previous chapter covered. Familiarity with symbolic links helps, but the chapter explains what you need.
Why some folders should not sync
iCloud Drive treats every file inside it as something to upload, track, and mirror to your other devices. That works well for documents and photos. It works badly for folders that hold thousands of small, generated files. Common examples:
node_modulesfrom a JavaScript project- Python virtual environments such as
.venv - Build output folders and package caches
- Large scratch folders that you can recreate at any time
These folders cause three problems. They use iCloud storage quota. They make the sync service work through huge numbers of tiny changes. They can also leave a project looking half-synced on a second Mac, where a few files have arrived and the rest have not.
If you keep projects under Desktop or Documents and have turned on Desktop and Documents syncing, those folders are uploaded too. You need a way to say "keep this folder on this Mac only."
How the .nosync suffix works
iCloud Drive skips any file or folder whose name ends in .nosync. Nothing else is configured. You rename the item, and the sync service stops uploading it.
The rule has some details:
- The suffix must be exactly
.nosync, in lowercase, at the end of the name.node_modules.nosyncis skipped.node_modules.NoSyncandnode_modules.nosync.bakare not. - It applies to the item itself and everything inside it. You rename the top folder only.
- It only matters inside a location that iCloud Drive manages. In a folder that is not synced, the suffix does nothing.
- It is a naming convention that the sync service honors. It is not a setting you can see in System Settings.
The problem with renaming alone
Many tools expect a fixed folder name. If you rename node_modules to node_modules.nosync, Node cannot find its packages. The usual fix is a symbolic link. A symbolic link (symlink) is a tiny file that points to another path. When a program opens the link, the system sends it to the target.
You rename the real folder, then create a symlink with the original name that points to it:
mv node_modules node_modules.nosync
ln -s node_modules.nosync node_modulesThe first command renames the folder. The second creates node_modules as a link to node_modules.nosync. The link uses a relative path, so it keeps working if you move the whole project folder.
After this, tools read and write through node_modules as before, while the real data sits in a name that iCloud Drive ignores.
A complete worked example
This sequence builds a small test project under Documents, excludes a folder, and checks the result. It assumes Desktop and Documents syncing is on. If it is off, run it in any folder under ~/Library/Mobile Documents/com~apple~CloudDocs instead.
cd ~/Documents
mkdir -p nosync-demo/cache
cd nosync-demo
echo "generated data" > cache/output.txt
mv cache cache.nosync
ln -s cache.nosync cache
ls -l
cat cache/output.txtThe ls -l output should show a line like this:
lrwxr-xr-x 1 you staff 12 27 Nov 12:53 cache -> cache.nosync
drwxr-xr-x 3 you staff 96 27 Nov 12:53 cache.nosyncThe leading l marks cache as a link, and the arrow shows its target. cat cache/output.txt prints generated data, which shows the link resolves through to the real folder.
To clean up, run rm -r ~/Documents/nosync-demo. When rm meets a symlink, it deletes the link, not the target. Because -r is used here, it also removes the real folder, since that folder sits inside the one you are deleting.
Doing it for a folder that already synced
If the folder is already in iCloud Drive, the rename has a side effect. To the sync service, node_modules disappeared and a differently named item that it ignores appeared. It removes node_modules from the cloud, and your other devices will delete their copies too.
Check these points before renaming:
- Make sure the folder holds nothing you cannot recreate. A package cache is safe. A hand-edited folder is not.
- Make sure the folder is fully downloaded on this Mac. A file shown with a cloud icon has no local copy, and the rename will leave you without it.
- Pause for a moment on other Macs. They will remove their copies of the folder, so a build running there may fail.
- Check iCloud.com afterwards to confirm the folder is gone from the cloud side.
What the other Mac sees
The symlink named node_modules has no .nosync suffix, so it syncs like any other small item. On a second Mac it arrives as a link that points to node_modules.nosync, and that target does not exist there. The link is dangling, and any tool that opens it fails with "no such file or directory."
This is correct behavior, not a sync fault. On the second Mac you recreate the folder, for example by running your package manager's install command. Many tools will write into the dangling link's target, which is a good outcome. Others will fail. If a tool refuses to proceed, create the target first:
mkdir node_modules.nosync
npm installYou now have two independent copies of the dependencies, one on each Mac, and the only thing they share is the link.
Checking that exclusion worked
The shell cannot show you sync state, so use several signals together:
ls -lconfirms the link and its target are what you expect.- In Finder, the
.nosyncfolder should not show a cloud or progress icon, which are the status icons covered earlier in this tutorial. Items that sync show them. - On iCloud.com, open the same location. The
.nosyncfolder should not appear. - In the iCloud storage list in System Settings, your total usage should stop growing as you build.
If the folder still appears on iCloud.com, check the spelling first. Then confirm you are looking at the real folder and not the symlink, which is expected to sync.
Undoing the exclusion
To bring the folder back under sync, reverse the steps. Remove the link first, then rename the folder:
rm node_modules
mv node_modules.nosync node_modulesRun rm without -r and without a trailing slash, so it removes only the link. Writing rm -r node_modules/ can follow the link and delete the contents of the real folder in some shells. Once the folder has its original name, iCloud Drive uploads all of it.
Alternatives and when to prefer them
.nosync is convenient but not always the best choice. Compare your options:
| Approach | Strength | Weakness |
|---|---|---|
| `.nosync` plus symlink | Keeps the project where it is, with one rename and one link | Dangling link on other Macs, and tools that recreate the folder can defeat it |
| Keep the project outside iCloud Drive, for example in `~/Developer` | No sync side effects at all, and no special naming | Project is not mirrored to your other devices |
| Version control such as Git on a remote host | Proper history and merging, and generated folders are listed in `.gitignore` | Needs a remote and some setup |
For source code, the second and third options are usually safer. Repositories contain a hidden .git folder with many small files that change often, and iCloud Drive can mishandle it when two Macs touch the same repository. Use .nosync for the case where you want a project folder in iCloud Drive and have a few specific generated folders to leave out.
Common mistakes
- Typing the suffix incorrectly, such as
.nosycor-nosync. The folder then syncs normally. - Creating the symlink with the wrong direction. The command is
ln -s TARGET LINKNAME, so the real folder comes first. - Using an absolute path in the link. That breaks when you move the project or use a different account name on another Mac.
- Forgetting to recreate the folder on other Macs, then reading the dangling link as a sync failure.
- Expecting
.nosyncto protect files from deletion. It only stops syncing and does nothing for backup, so back up that data another way if it matters.
Exercise
You run mv build build.nosync in a synced project folder and then ln -s build.nosync build. A colleague with the same project on a second Mac reports that build there gives "no such file or directory." What is happening, and what do you do?
Show answer
The build symlink synced, but the real folder build.nosync did not, because iCloud Drive skips names ending in .nosync. On the second Mac the link is dangling. This is expected. Create the target there, for example with mkdir build.nosync, or run the build command so the tool creates its output.
Exercise
Why should you run plain rm node_modules and not rm -r node_modules/ when removing the symlink to undo the exclusion?
Show answer
Plain rm removes only the link. With a trailing slash and -r, the shell can resolve the link to the real folder and delete its contents, which is not what you want when you plan to rename node_modules.nosync back to node_modules.