Fix macOS .nofollow Directories Causing Infinite Backup Loops

Summary

A .nofollow directory on macOS is a special placeholder created by the file system when a folder is being indexed or backed‑up and a recursive copy would otherwise cause an infinite loop. The folder appears to contain duplicated data and can balloon to many terabytes, but the data is not actually stored multiple times. The fix is to identify the offending process, stop it, and remove the placeholder safely.

Root Cause

  • macOS creates .nofollow when a recursive operation (Time Machine, Spotlight, rsync, backup scripts) encounters a directory that would copy itself.
  • The file system records the directory as a hard‑link loop placeholder; its size is reported as the sum of the linked content.
  • The placeholder is a metadata‑only entry; no real duplicate data occupies disk space.

Why This Happens in Real Systems

  • Backup tools often traverse the entire hierarchy; without safeguards they may try to copy the backup directory back into itself.
  • Spotlight indexing can trigger the creation when it hits a symbolic link loop.
  • Custom scripts that use cp -R or rsync -a without --exclude for the backup destination repeat the copy process.
  • The OS protects against infinite recursion by substituting the .nofollow marker.

Real-World Impact

  • Disk‑space confusion: du and Finder report enormous sizes, leading users to think the drive is full.
  • Performance degradation: Scanners and backup jobs waste CPU cycles traversing the placeholder.
  • Potential data loss: If a user force‑deletes the folder without stopping the offending process, the backup may be corrupted.
  • Alert fatigue: Repeated alerts from monitoring tools misinterpret the size as a genuine growth problem.

Example or Code (if necessary and relevant)

# Find .nofollow directories
find / -type d -name ".nofollow" 2>/dev/null

# Stop a runaway Time Machine backup
tmutil stopbackup

# Safely remove the placeholder (after stopping the offending process)
sudo rm -rf /path/to/.nofollow

How Senior Engineers Fix It

  • Identify the source: Check logs (/var/log/system.log, Time Machine status, Spotlight indexing queue) to see which service created the placeholder.
  • Pause the service: Use tmutil stopbackup, mdutil -i off, or kill the offending script.
  • Validate the real data: Run du -sh on parent directories to confirm actual used space.
  • Remove the placeholder: After confirming no active process needs it, delete with sudo rm -rf.
  • Add safeguards:
    • Exclude backup destinations from backup jobs (--exclude="/Volumes/Backup").
    • Use rsync --one-file-system to avoid crossing filesystem boundaries.
    • Configure Spotlight to ignore specific paths (mdutil -i off /path).
  • Monitor: Set up alert thresholds on real disk usage, not on placeholder size.

Why Juniors Miss It

  • Lack of file‑system knowledge: They may assume the reported size is actual data.
  • Relying on UI tools: Finder’s size display can be misleading; juniors don’t verify with CLI tools.
  • Skipping root cause analysis: They delete the folder without stopping the process, causing repeat occurrences.
  • Inexperience with backup tools: Not aware of recursive copy pitfalls and proper exclusion patterns.

Leave a Comment