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!
- How to list all users in Mac Terminal
- Docker Desktop needs privileged access macOS
- Mac: How to show count of files and folders in Finder
- How to Change Background Color TextEdit on Mac
- How to adjust MacBook Desktop icons size
- Test internet speed using macOS Terminal command
- How to change the default font and text size in Microsoft Excel for Mac
- How to install Java on macOS [Big Sur]
- How to come out of dquote prompt in Terminal - macOS/Linux
- How to Increase MacBook Trackpad Cursor Speed on macOS Ventura/Sonoma
- Fix: Microsoft Excel Quit Unexpectedly on Mac
- How to Adjust macOS System Font Size
- How to Quit Applications on Mac Using Terminal
- How to check zsh installed version using terminal
- Two Ways to Extract rar (*.rar) files on Mac
- How to Right Click on Mac Desktop?
- How to Add Brew to PATH M1/M2 Mac
- How to search (find) in macOS Terminal Console Text
- macOS 13 Ventura - The New About this Mac Window
- TextEdit Get the count of lines in a file
- How to run .sh file in Mac Terminal
- Google Search Hot Trends Screensaver for Mac OS X
- Check Reboot History Mac
- [Solution] Mac Update Stuck Preparing macOS Ventura 13.0 About 30 minutes remaining
- Display Safari URL address link on hover
- How to Open Calculator using Mac Terminal - MacOS
- Hurry! Uninstall Adobe Flash Player - End Of Life, support end in December 2020 - News
- Fix: Microsoft Excel Quit Unexpectedly on Mac - MacOS
- How to Set Permanent ruler in Sublime Text - Sublime-Text
- Mac Shortcut for Fullscreen mode for App Window - MacOS
- Get the current timestamp in Java - Java
- How to Toggle Dark and Light Mode on macOS Sonoma 14 - MacOS
- Java: How to Filter a List using Predicate - Java