Guides / Terminal

How to find files on Mac from the Terminal

To search for a file in Terminal on a Mac, type mdfind -name report for a quick answer from the Spotlight index, or find ~ -iname "*report*" to read the folders themselves, which is slower but misses nothing. macOS also has locate, which is turned off until you build its database, and Everything Locator adds el, the quickest of the four because it answers from an index of every file name.

Works on macOS 15 and later. Updated December 5, 2026.

1. el: an index of every file name

Everything Locator (free to try) keeps an index of the names, paths, sizes and dates of your files and updates it as files change. Its command-line companion el sends a search from Terminal to that index, so the answer comes back at once, as plain paths you can pipe into other commands. el is part of Everything Locator Pro, an optional subscription, and the app has to be running. Searching in the app's own window takes the same queries and does not need Pro.

CommandFinds
el search invoice 2026names that contain both words
el search report ext:pdf dm:thisyearPDFs with "report" in the name, changed this year
el search '*.mov' 'size:>1gb'movies over 1 GB
el search content:invoice ext:pdfPDFs whose text has the word, from the Spotlight index
el search --in ~/Projects ext:swiftSwift files inside one folder
el search -l -s modified -n 20 dm:todaythe 20 newest items changed today, with size and date
el search -0 --all ext:log 'size:>100mb' | xargs -0 ls -lhevery log over 100 MB, handed to ls

The words after el search are one search in the syntax of Everything by voidtools; the Everything search syntax cheat sheet lists the operators. Put a word that holds *, ?, >, <, | or ! in single quotes so the shell passes it on as typed.

Two limits to know. el never shows what is inside files: its content: search (Everything Locator 2.0.2 or later) asks Spotlight, the index mdfind uses too, so it finds only what Spotlight has indexed and matches words, not exact phrases or code; for those, use grep, below. And it sees the folders the app indexes: files under ~/Library or in other hidden folders appear only after you turn on Include hidden files in Settings › Indexing.

2. find: read the folders themselves

find comes with macOS. You give it a folder to start in and one or more tests, and it walks through every folder below the start and prints each item that passes.

# name contains "report", upper or lower case, in your home folder
find ~ -iname "*report*" 2>/dev/null

# exact name, case as typed
find ~/Documents -name "Budget 2026.xlsx"

# only files (f) or only folders (d)
find ~/Projects -type d -name "build"

# PDFs changed in the last 7 days
find ~/Downloads -iname "*.pdf" -mtime -7

# files over 100 MB
find ~ -type f -size +100M 2>/dev/null

# look only two levels deep
find ~ -maxdepth 2 -iname "*.zip"

Keep the pattern in quotes, or the shell tries to expand the * itself. -name matches the whole name, so -name report finds only an item called exactly "report"; add the stars to match part of a name. Several tests in a row must all be true.

find needs no index, so it sees hidden files, new files and external drives right away (more ways to find hidden files). The price is time: it reads every folder on every run, and a search of a whole home folder can take a minute or more. Start in the smallest folder you can.

"Operation not permitted" and "Permission denied". find prints one of these for each folder it is not allowed to read and carries on with the rest. 2>/dev/null at the end hides the messages. macOS asks before Terminal may read your Desktop, Documents and Downloads folders; the choices are kept in System Settings › Privacy & Security › Files & Folders.

3. mdfind: ask the Spotlight index

mdfind is Spotlight for the command line. It answers from the index macOS already keeps, so it is quick, and it can match the text inside documents as well as names.

# file names that contain "report" (ignores case)
mdfind -name report

# the same, inside one folder
mdfind -onlyin ~/Documents -name report

# any file that mentions the word, in its name or its text
mdfind -onlyin ~/Documents "quarterly budget"

# how many matches, without the list
mdfind -count -name invoice

# by extension
mdfind -onlyin ~ "kMDItemFSName == '*.pdf'c"

# Markdown files changed in the last 7 days
mdfind -onlyin ~ "kMDItemFSName == '*.md'c && kMDItemFSContentChangeDate >= \$time.today(-7)"

# files over 1 GB (the size is in bytes)
mdfind -onlyin ~ "kMDItemFSSize > 1000000000"

Without -name, a plain word is compared with everything Spotlight knows about a file, including its contents, so the list is longer. -0 ends each path with a NUL character for xargs -0, and -live keeps the search running and updates the count as files change. To see which attributes a file has, run mdls on it: mdls ~/Desktop/photo.heic. Searches by kind and extension are covered in how to search by file extension or file type on Mac.

mdfind knows only what Spotlight has indexed. It leaves out hidden folders such as ~/Library and anything excluded in the Spotlight settings, and it returns nothing when indexing is off. mdutil -s / shows whether indexing is enabled for the startup disk; if it is and files are still missing, see Finder or Spotlight search not working.

4. locate: fast, but off by default

locate searches a database of path names, and a word without wildcards matches any part of the path: locate -i nginx.conf (-i ignores case). On a Mac the database does not exist until you ask for it. The first time you run locate, it says so and prints the command that creates it:

sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist

That starts a system job, so run it only if you want the database. Its manual page lists two limits that matter on a Mac. The database is typically rebuilt once a week, so new files are missing and deleted ones still show up. And it is built by a user with no rights of its own, which skips every folder that is not readable by everyone; on a Mac that includes your Desktop, Documents and Downloads folders. locate is fine for system and configuration files under /usr, /etc or /Library, and of little use for your own documents.

find vs mdfind vs locate: which to use

CommandSearchesSpeedMisses
findthe folders on disk, as they are nowslow on large foldersnothing it is allowed to read
mdfindthe Spotlight index: names, contents, metadatafasthidden and excluded folders; everything when indexing is off
locatea database of paths, rebuilt about weeklyfastrecent files; folders only you can read
elEverything Locator's index: names, paths, sizes, dates; content: asks Spotlightfastfolders the app does not index; for content:, what Spotlight has not indexed

If you would rather not use Terminal at all, how to find files on Mac covers Spotlight and Finder search, and how to find large files on Mac has the size searches.

FAQ

How do I search for a file by name in Mac Terminal?

Open Terminal and type mdfind -name followed by part of the name, for example mdfind -name budget. If the file is hidden or Spotlight does not find it, use find ~ -iname "*budget*", which reads every folder in your home folder.

What is the difference between find and mdfind?

find walks through the folders each time you run it, so it is complete and slow. mdfind asks the Spotlight index, so it is quick and can match text inside documents, but it knows only what Spotlight has indexed.

Does locate work on a Mac?

Yes, after you create its database with the launchctl command that locate prints on its first run. The database is rebuilt about once a week and leaves out folders that only your account can read, so it suits system files better than your own documents.

Why does mdfind return nothing?

Either Spotlight has not indexed the place the file is in (a hidden folder, an excluded folder, some external drives), or indexing is turned off. Check with mdutil -s /, and use find for the folders Spotlight skips.

How do I search inside files from Terminal?

mdfind "some words" searches the text Spotlight has indexed. grep -ril "some words" ~/Documents reads every file in a folder and lists the ones that contain the words; it works on plain text files such as notes, code and logs. With Everything Locator Pro, el search content:invoice ext:pdf asks the same Spotlight index and combines the word with a type, size or date.

Search your whole Mac by name, in the app or in Terminal

Everything Locator lists every match as you type, and el brings the same index to the command line.

Mac App Store