Use of "locate" command

I am trying to teach myself some Linux commands using Ubuntu Mate 15.04 and am having trouble with the locate command. I am in a directory that contains a file called testfile.txt. I then run the following commands:

sudo updatedb
locate testfile

However, the system does not return any results. Running ls testfile* does return the file name.

Thanks!

Just for curiosity, are you reading this:
The Linux Command Line ?

Anyway, I tested your example in 15.10 and IT WORKS

I upgraded to 15.10 last night and tried it again but still no luck. Is there a way to reinstall that command?

I don’t really have a structured approach to my self-education (though I could really use one!). For now, I’ve been Googling various sites and working my way through the Linux Foundation’s Introduction to Linux course.

But I will take a look at your suggestion too! Thanks!

The command is in the package mlocate, so you could do so:

sudo apt-get purge mlocate
sudo apt-get install mlocate

Thank you for the reply, lah7. I tried your suggestion (which is what I was looking for) but unfortunately, locate still can’t seem to locate a simple test file, even after I ran sudo updatedb.

Oh well, no big deal. I think there are still other ways to find files via the command line. It’s just curious that this didn’t work. The funny thing is that when I tried it, it returned:

/usr/share/perl15/Mail/Mailer/testfile.pm

but not the testfile.txt that is in the directory from where I ran the command!

Which directory are you in? eg. /home/spython

pavlos@canyon:~$ touch testfile.txt
pavlos@canyon:~$ sudo updatedb
pavlos@canyon:~$ locate testfile
/home/pavlos/testfile.txt
/usr/share/perl5/Mail/Mailer/testfile.pm