In the previous post I showed you how to use the find command. Find works on any Linux system. But it does require some effort.
I’ll show you another way to find files by name, with the locate command.
The first thing we have to do, is to install the command. It does not come standard on most Linux distributions. As always ymmv applies.
1. Let’s get started! First thing we want to do is install locate.
sudo apt-get install locate
This will install the locate command. But we are not quite finished. Locate uses a database, so we must first build the database. The database is updated daily. So additions you make during the day, won’t show up until the next day usually.
2. Here’s how to build the database:
sudo updatedb
This is going to take sometime, as it has to index every file. So be patient.
Made a lot of changes, and want to update the database now? You can run updatedb ad hoc (as needed). Just follow the step above.
Using our potato example from the previous post:
nwayno@Homer:~$ locate potato
/home/misc/oldwindows/wp51/recipes/leekpotato.txt
/home/misc/oldwindows/wp51/recipes/potato.txt
/home/misc/oldwindows/wp51/recipes/potato.wp
/home/misc/oldwindows/wp51/recipes/stuffed baked potatoes.wp
/home/nwayno/potato_head.jpg
/home/nwayno/recipes/leekpotato.txt
/home/nwayno/recipes/potato.txt
/home/nwayno/recipes/potato.wp
/home/nwayno/recipes/stuffed baked potatoes.wp
/home/nwayno/wp51/recipes/leekpotato.txt
/home/nwayno/wp51/recipes/potato.txt
/home/nwayno/wp51/recipes/potato.wp
/home/nwayno/wp51/recipes/stuffed baked potatoes.wp
Notice that it found ALL files that contained potato somewhere in the file. No wild cards needed. Neat, huh?
If you want any of the recipes, let me know!
Related Articles
1 user responded in this post
FWIW, if using a redhat/centos/fedora system, just substitute “yum install locate” in place of the “apt-get install locate” used on debian derived distros.