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
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
- How to show line numbers in Nano on Mac
- How to install Jupyter Notebook on macOS Sonoma
- How to Disable Remote Management using Mac Terminal
- Test internet speed using macOS Terminal command
- Docker Desktop needs privileged access macOS
- Google Search Hot Trends Screensaver for Mac OS X
- How to do calculations in Mac Terminal
- How to make TextEdit the default text Editor on Mac
- How to Show Full Website Address on Safari for Mac (Ventura/Sonoma)
- The Zsh Shell - Mac Tutorial
- Opening mac Terminal
- How to change the name of your Mac running on macOS Ventura 13
- How to find the Battery Cycle Count on macOS Ventura
- How to set an emoji as Zsh terminal prompt in macOS
- How to access Trash Folder using Mac Terminal Command
- macOS Ventura XCode Command Line Tools Installation
- Hide Bluetooth icon on Mac Menu Bar macOS Ventura 13
- How to run .sh file in Mac Terminal
- Terminal Command to get the list of available shells in macOS
- How to see Storage Information on macOS Ventura
- How to Go To /usr/local/bin on Mac Terminal?
- How to do screen recording on Mac
- How to Find File and Directory Size in Mac Terminal
- Open .bash_profile File in TextEdit using Terminal
- Remove Now Playing icon from macOS Big Sur Menu Bar
- How to restart WiFi using Crosh Terminal (ChromeOS Chromebook) - Chrome
- How to Turn Off Assistive Access on iOS 17 - iOS
- Git Remove Untracked Files using Command - Git
- Cannot open or preview pdf with view only and restricted download access in Microsoft Teams - Teams
- Fix: NoSuchBeanDefinitionException: No bean named x available (application-config.xml) - Java
- How to Uninstall Brew on Mac - MacOS
- Wrap Text in Python using - textwrap module - Python
- 45: Take two strings and concatenate them. [1000+ Python Programs] - Python-Programs