mdutil - macOS


Overview

mdutil is a command-line utility for managing the macOS Metadata Store, which helps improve search performance and provides data for Spotlight.

Syntax

mdutil [-a] [-d] [-E] [-i] [-v] [-s] [-p]

Options/Flags

  • -a: Scan all files on all local volumes.
  • -d: Disable Spotlight indexing.
  • -E: Enable Spotlight indexing.
  • -i: Rebuild the metadata store.
  • -v: Verbose output.
  • -s: Show metadata store status.
  • -p [volume path]: Scan a specific volume.

Examples

  • Enable Spotlight indexing:
mdutil -E
  • Disable Spotlight indexing:
mdutil -d
  • Rebuild the metadata store:
mdutil -i
  • Show metadata store status:
mdutil -s
  • Scan a specific volume:
mdutil -p /Volumes/MyVolume

Common Issues

  • Spotlight is not indexing files: Ensure indexing is enabled (mdutil -s) and rebuild the metadata store (mdutil -i) if necessary.
  • Search results are inaccurate: Rebuild the metadata store (mdutil -i) or disable and re-enable indexing (mdutil -d and mdutil -E).

Integration

  • Combine mdutil with find to scan specific file types or directories:
find /path/to/directory -exec mdutil -i {} \;
  • Use mdutil with launchctl to control the Spotlight indexing process:
sudo launchctl unload -w /System/Library/LaunchAgents/com.apple.metadata.mds.plist
sudo launchctl load -w /System/Library/LaunchAgents/com.apple.metadata.mds.plist
  • mdls: Display metadata for a specific file or directory.
  • mdimport: Import metadata into the Metadata Store.
  • Spotlight documentation