2 min read

Locating Files with Find on macOS Tahoe

While Spotlight is great for quick, indexed searches, the find command is the ultimate tool for locating files based on specific criteria like size, modification date, or permissions directly from the terminal.

Basic Syntax

The structure of the command is:

find [path] [expression]
  • [path]: Where to start searching (e.g., . for current directory, ~ for home, / for root).
  • [expression]: The criteria to match.

Finding by Name

To find a file by its name:

find . -name "config.json"

To search regardless of case (e.g., matching "Image.png" and "image.PNG"):

find ~ -iname "image.png"

Finding by Type

You can filter results to show only files or only directories.

  • -type f: Files
  • -type d: Directories

Example: Find all directories named "build":

find . -type d -name "build"

Finding by Size

You can search for files based on their file size.

  • +: Greater than.
  • -: Less than.

Example: Find files larger than 100MB:

find ~ -size +100M

Finding by Time

  • -mtime: Modification time (in days).
  • -atime: Access time (in days).

Example: Find files modified in the last 7 days:

find . -mtime -7

Executing Commands on Results

The most powerful feature of find is performing an action on every file it finds using -exec.

Example: Find all .tmp files and delete them:

find . -name "*.tmp" -exec rm {} \;
  • {}: Placeholder for the found filename.
  • \;: Ends the command.

For more on general terminal usage, refer to Getting Started with macOS Tahoe.