28

In Linux, we can use the locate command to find the files from the terminal. Is there any command available for Mac OSX which works same as the locate command?

I want to find a file in complete filesystem accessible by User(Me) in mac OSX. Can it be done with some command from the terminal?

This command should show me the list of all paths where the file of the same name is available.

Abhishek
  • 3,304
  • 4
  • 30
  • 44
  • 1
    Have you tried `find` ? – 123 Jul 14 '16 at 12:15
  • 1
    I think, find command works only for the current directory. – Abhishek Jul 14 '16 at 12:17
  • Please give me example command if you know how to search the whole filesystem with find command. – Abhishek Jul 14 '16 at 12:18
  • 6
    Or even, `locate`? That command originated in 4.4BSD, was introduced to FreeBSD in version 2.2, and has been included in every version of OS X. Also, this is off-topic for StackOverflow, as it's not a programming question. – ghoti Jul 14 '16 at 12:23
  • The service that builds the database for `locate` isn't running by default, although running `locate` gives you instructions for starting it. – chepner Jul 14 '16 at 12:27
  • This is not the off-topic for StackOverflow. This is completely appropriate question for the included tags. You can find most voted questions which doesn't include code but those are really important for coding or any other programmer. – Abhishek Jul 14 '16 at 12:28
  • http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in – Abhishek Jul 14 '16 at 12:28
  • http://stackoverflow.com/questions/592620/check-if-a-program-exists-from-a-bash-script – Abhishek Jul 14 '16 at 12:28
  • 2
    I'm voting to close this question as off-topic because it belongs to http://apple.stackexchange.com – Schlaus Jul 14 '16 at 12:52
  • It doesn't belong only to apple community because to know its answer someone should know how locate command work which is the part of linux community – Abhishek Jul 14 '16 at 13:09
  • `locate` is _not_ a Linux command and is included in OSX as much as it is included in Linux - perhaps not active by default, for more info, please consult [this](http://apple.stackexchange.com/questions/188799/cannot-locate-app-locate-not-working) and [this](http://apple.stackexchange.com/questions/228164/is-there-a-way-to-use-update-command-to-locate-files-on-os-x-without-having-to-r) AskDifferent post, where this question might have a better chance. – user3078414 Jul 14 '16 at 13:40
  • I agree but linux users are much more familiar with this command. – Abhishek Jul 14 '16 at 15:32
  • 2
    Use **findy**: https://github.com/f1lt3r/findy... `npm install findy -g`, `findy '**/notes.txt'` – f1lt3r Jul 06 '17 at 05:29
  • Why won't you try activating locate on mac os? ```sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist``` – wintermute Jan 16 '18 at 23:02

1 Answers1

58

I guess the mdfind command is what your are looking for:

mdfind -name test.pdf
Julian
  • 1,694
  • 22
  • 29