In order to find a file on the Mac Terminal, you can make use of the find or mdfind command.
find – walk a file hierarchy
Syntax:
find <path-to-find> -name <name-of-file-to-find>
Example:
% find /Users/code2care/Desktop -name key.pem
Note: You might get pop-up alerts saying "Terminal would like to access your XXXX", which you need to allow to look for the file and you may see console logs saying Operation not permitted
![Find File on macOS using find and mdfind command Find File on macOS using find and mdfind command](https://code2care.org/macos/find-a-file-using-filename-mac-terminal/images/Find File on macOS using find and mdfind command.jpg)
mdfind command
mdfind – finds files matching a given query
Example:% mdfind -name key.pem
2022-10-31 23:37:51.443 mdfind[97925:2194875] [UserQueryParser] Loading keywords and predicates for locale "en_US"
2022-10-31 23:37:51.443 mdfind[97925:2194875] [UserQueryParser] Loading keywords and predicates for locale "en"
/Users/code2care/Desktop/key.pem
/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/site-packages/future/backports/test/ssl_key.pem
Note: The mdfind command makes use of the Spotlight database to provide search results, so it is faster compared to find command. As it does not have to do the scanning the whole file system for the query, but on the other side, its database may not be up-to-date as indexing is delayed so you may not find the file that may exist.
Facing issues? Have Questions? Post them here! I am happy to answer!
Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.
Follow him on: X
You can also reach out to him via e-mail: rakesh@code2care.org
- Fix: grunt: command not found (Mac/Windows)
- AppleScript Example with TextEdit
- How to copy Password of Wifi on your Mac
- Install OpenJDK Java (8/11/17) versions using brew on Mac (Intel/M1/M2)
- How to check if a port is in use using terminal [Linux or macOS]
- Cut, Copy and Paste Keyboard Shortcuts on Mac Keyboard
- [macOS] NetBeans IDE cannot be installed. Java (JRE) found on your computer but JDK XX or newer is required.
- How to Remove Widgets from macOS Sonoma 14 Desktop
- Turn off Auto-Capitalization on macOS Ventura 13
- How to Go To /usr/local/bin on Mac Terminal?
- How to Open TextEdit on Mac
- Mac: How to Open Android Studio from Terminal
- How to change the default location of Mac Screenshot
- Display Seconds in Digital Clock on Mac Menu Bar [macOS]
- How to install homebrew (brew) on M1 Mac
- Must Know Homebrew Commands for Mac/Linux Users
- Steps to Uninstall Roblox on Mac (macOS)
- How to change the System Settings Sidebar icon size Mac Ventura 13
- How to set Out Of Office (OOO) on Outlook for Mac [Updated 2023]
- Trigger Notification Center Message using Mac Terminal Command
- [fix] macOS Ventura - Python3 xcrun: error: invalid active developer path missing xcrun at CommandLineTools
- How to Install Rust Language on Mac (macOS)
- How to minimize all Windows in Mac
- Display ls command file sizes in KB (kilobytes) MB (megabytes) or GB (gigabytes) [Linux/macOS]
- How to make TextEdit the default text Editor on Mac
- Use Netbeans keyboard shortcuts in Android Studio - Android-Studio
- Android Studio setup was canceled - How to resume - Android-Studio
- Online Timestamp Converter (Epoch/Unix) Tool - Tools
- How to Remove Widgets from macOS Sonoma 14 Desktop - MacOS
- Remove Possible Data Loss Message from Microsoft Excel - Microsoft
- Find Duplicate Files using Mac Terminal Command - MacOS
- Tesla hit by a complete network and mobile app outage - 23 Sept 2020 11am ET (US and Europe) - News
- Open Current Directory in Finder using Mac Terminal - MacOS