Skip to content

Locating files in terminal on mac (edit: using mdfind)

September 20, 2012

As is usual, this post is purely so that I don’t forget something technical (EDIT: see the edit at the end for the most useful advice!).

BACKGROUND: I had to update to JAGS 3 today, because the new version of rjags now requires it. I ran into an installation issue that (fortunately) several people have had before. Because of this issue, I had to manually uninstall my old version of JAGS, which requires finding where all of the JAGS files are hiding on my system.

HOW TO DO IT: This is probably not the best (and certainly not the fastest!) way to locate files with particular characteristics, but this worked for me to solve my JAGS installation problems. First you need to `update your database’. On linux this is done using the updatedb command, but on mac its annoyingly called something slightly different: locate.updatedb. To make matters more weird, I needed to supply the full path of this executable when running it. I also needed to run it as a `super user’, which means you need to use the sudo command first (this command asks you for a password so you need administrative privileges to use this technique). For a fun intro to sudo, see this. So here’s how to update the database,

sudo /usr/libexec/locate.updatedb

Once the database is updated, its simple to locate all kinds of files. Here’s what I needed,

locate  'jags'

which gave me a list of the location of all files and directories with the string 'jags' in their names.

ISSUES: The locate command is extremely fast, but it requires that you first run locate.updatedb, which is extremely slow. I think the find command is better overall for speed, but I’m no expert that’s for sure.

NOTE: This worked on my system, and may not work on yours.

EDIT: I have since discovered that the mdfind command is much more useful than what I wrote about above. However, the syntax required for using mdfind doesn’t seem to be very well documented yet. But for just plain vanilla searching for a file use this:

mdfind -name filename

And if this doesn’t work (e.g. the file’s invisible or something), try this:

mdfind 'kMDItemFSName == "filename"'
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: