Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Locate command can't find anything inside Documents folder on mac

As it says in the description. I first check our database is up to date

mh547:bin crashandburn4$ sudo /usr/libexec/locate.updatedb
Password:       #password entered and function executed without errors

I then try and search for something inside my Documents folder

mh547:bin crashandburn4$ cd ~/Documents/
mh547:Documents crashandburn4$ ls
    Mamp_workspace/                         Scenarios.docx                          gc01/
mh547:Documents crashandburn4$ locate Scenarios.docx    #nothing returned

I then try another random folder:

mh547:Documents crashandburn4$ cd ..
mh547:~ crashandburn4$ ls
    Applications/                Movies/                      drawable/                    untitled-2.pdf
    Desktop/                     Music/                       drawable-xhdpi/              untitled-2.synctex.gz
    Documents/                   Pictures/                    dwhelper/                    untitled-2.tex
    Downloads/                   Public/                      linux_ssh*                   website-terminal-copy-paste
    Dropbox/                     Samsung/                     scripts/                     workspace/
    Google Drive/                Sites/                       untitled-2.aux               workspace_copy_to_linux*
    Library/                     android-sdks/                untitled-2.log
mh547:~ crashandburn4$ locate website-terminal-copy-paste 
/Users/crashandburn4/website-terminal-copy-paste #correct result returned

can anyone help me? I've been stuck on this for a good half hour or so.

like image 703
Mike H-R Avatar asked Apr 08 '13 19:04

Mike H-R


2 Answers

As pointed out by plundra, that's because the locate OSX ships with is old and crippled and doesn't index and/or report files which are not readable by nobody, even when run as root. What you can do though is either install homebrew and then GNU locate, or, as suggested here use mdfind -name instead (I don't have an OSX box at hand to test this).

like image 132
Adrian Frühwirth Avatar answered Oct 05 '22 03:10

Adrian Frühwirth


It's because your Documents-folder isn't world readable, which is a good thing, specially on shared systems.

The BUGS section of the locate(1) man-page explains it:

The locate database is typically built by user ''nobody'' and the locate.updatedb(8) utility skips directories which are not readable for user ''nobody'', group ''nobody'', or world. For example, if your HOME directory is not world-readable, none of your files are in the database.

Try running ls -ld ~/Documents and you'll see the permissions. Wikipedia have an article on Unix permissions if you are unfamiliar with these.

like image 41
plundra Avatar answered Oct 05 '22 03:10

plundra