locate doesn't find all the files it should

3

I type in locate gmp.h at the prompt and get the following:

/usr/src/linux-headers-3.13.0-24/include/linux/igmp.h
/usr/src/linux-headers-3.13.0-24/include/uapi/linux/igmp.h
/usr/src/linux-headers-3.13.0-24-generic/include/linux/igmp.h

But when I do ls /usr/include/x86-64-linux-gnu/ I see this:

a.out.h  asm  bits  c++  fpu_control.h  gmp.h  gnu  ieee754.h  sys

Why isn't locate locating /usr/include/x86-64-linux-gnu/gmp.h?

edit: ls -l /usr/include/x64-64-linux-gnu/gmp.h says this:

ls: cannot access /usr/include/x64-64-linux-gnu/gmp.h: No such file or diretory

Why would ls /usr/include/x86-64-linux-gnu/ say it exists when ls -l /usr/include/x64-64-linux-gnu/gmp.h says it doesn't?

A screenshot:

enter image description here

neubert

Posted 2014-08-23T15:03:52.950

Reputation: 3 991

1When were the files you search for created? When did you last update your locate database? (Before or after adding the files) ? – Hennes – 2014-08-23T15:06:20.970

1A few minutes ago. I didn't know the DB had to be updated lol. Doing so resolved the issue - thanks! – neubert – 2014-08-23T15:11:01.360

Could you run "ls -l /usr/include/x86-64-linux-gnu/gmp.h" and add the output to your question? – Kenster – 2014-08-23T15:22:43.173

Done. See my updated question – neubert – 2014-08-23T15:27:17.357

Try "ls -l /usr/include/x64-64-linux-gnu". My guess is that the gmp.h entry is a symbolic link pointing to a nonexistant file. – Kenster – 2014-08-23T15:29:37.203

It looks like it exists to me when I do ls -l. I've updated my post with a sreenshot.. – neubert – 2014-08-23T15:37:45.403

1I've removed my answer. You've been saying the file is in /usr/include/x86-64-linux-gnu/. But according to your screenshot, it's actually in /usr/include/x86_64-linux-gnu/ (underscore instead of dash). – Kenster – 2014-08-23T16:13:30.363

Answers

4

locate does not find files on the filesystem. Instead it searches in a database which contains all files.

This database it usually updated once per day, typically around 3 AM.

You can update it manually with command such as updatedb (or if not logged in with sufficient credentials: sudo updatedb). For more information see man updatedb.


Based on your post which included /usr/src/linux-headers-3 I assumed that you are running this on a linux distribution. On other operating systems the locate command might work slightly different. E.g. On FreeBSD the command to manually update the locate database is to run /usr/libexec/locate.updatedb which gets weekly updated from /etc/periodic/weekly/310.locate.

Hennes

Posted 2014-08-23T15:03:52.950

Reputation: 60 739