LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   locate command appears not to work (https://www.linuxquestions.org/questions/linux-newbie-8/locate-command-appears-not-to-work-4175518120/)

Oisin 09-10-2014 09:29 AM

locate command appears not to work
 
Hi,

I was testing out the locate command for finding things. If I type:
locate <randomShortString>
it will generally return multiple hits as there are some dir or filename which happen to include <randomShortString>
when I tried to use it to find files that I had created myself it failed
I had created files indep.npz and indep.txt yesterday and when I type
locate indep
It returns nothing. So I though maybe the db had not been updated so I manually issued the command:
sudo updatedb
but locate indep still returns nothing despite the files clearly being present. So, can anyone explain this ?
On a related note the man page for updatedb lists the EXIT_STATUS of updatedb as 0 on success, 1 on error.
How do I determine the EXIT_STATUS for a call to a command ? It clearly isn't being sent to stdout as I'm seeing neither 0 nor 1 when I call updatedb. Seeing the exit status might allow me to figure out if it is the updatedb or the locate that is not behaving as expected.

Thanks,

Oisin.

keefaz 09-10-2014 09:39 AM

To see the exit status of any command in shell, just after it terminates, use:
Code:

echo $?
Not sure why locate doesn't find your files after you updated the db... Are you sure of the file names?

Oisin 09-10-2014 09:56 AM

Quote:

Originally Posted by keefaz (Post 5235593)
To see the exit status of any command in shell, just after it terminates, use:
Code:

echo $?
Not sure why locate doesn't find your files after you updated the db... Are you sure of the file names?

Okay so the EXIT_STATUS of the updatedb is 0 indicating success, but the locate command still fails to find my files. The EXIT_STATUS of the call to locate is 1 which could indicate no matches or an error. So it seems that it is the locate command that is at fault but I cant figure out why. I am using Ubuntu and the files in question are in my home directory. When installing Ubuntu I did specify that my home dir should be encrypted, could this be the source of the problem ?

Thanks,

Oisin.

pan64 09-10-2014 09:59 AM

you can check the man page of locate and updatedb to see how they are working. Especially updatedb -v will print the files it found. and also you can check the config file.

Oisin 09-10-2014 10:53 AM

I've had a look at the man pages for locate and updatedb and I can't see anything that would explain why locate isn't finding my files for example:

oisin@oisin-MXC051:~$ pwd
/home/oisin
oisin@oisin-MXC051:~$ locate oisin
/home/oisin
/var/lib/AccountsService/users/oisin
/var/tmp/audacity-oisin
oisin@oisin-MXC051:~$ tree
.
├── Desktop
├── Downloads
│** ├── audacity-minsrc-2.0.5.tar.xz
│** ├── test.mp4
│** └── Water_Butt_1.mp4
├── examples.desktop
├── indep.jpg
├── indep.npz
├── Music
├── Pictures
│** └── 1410106810515.jpg
├── Public
├── Templates
├── tmp
│** ├── 1.txt
│** ├── indep
│** ├── indep.txt
│** ├── ipFile
│** ├── ls
│** ├── mlocate.db
│** ├── new1
│** ├── nua
│** │** └── fileNua.txt
│** ├── opFile
│** ├── seal
│** └── seal.txt
└── Videos

12 directories, 15 files
oisin@oisin-MXC051:~$

My user dir is /home/oisin and the tree command shows clearly that it contains many files and subdirs (most of which have existed since Linux was installed) yet the locate command only returns one result: '/home/oisin' when clearly it should also contain an entry for each of the objects below /home/oisin

Anyone have any ideas why this is happenning? At the moment all I can thing is that it has something to do with the fact that I specified that my home dir should be encrypted when installing Linux but neither locate nor updatedb mentions having any problems with encrypted dirs.

cepheus11 09-10-2014 11:38 AM

There might be directories/filesystems to be excluded in updatedb's configuration. Locations like /media or /run/media are often excluded by default, as are filesystems usually used on removable media (like UDF). Check if this is the case for you

If locate can find other files in the same directory, then the cause must be different.

keefaz 09-10-2014 11:41 AM

Maybe check /etc/updatedb.conf, as pan64 and cepheus11 suggested

Oisin 09-10-2014 12:50 PM

Quote:

Originally Posted by keefaz (Post 5235654)
Maybe check /etc/updatedb.conf, as pan64 and cepheus11 suggested

Indeed, I didn't know where to find updatedb.conf but upon inspecting it I see:

PRUNEPATHS="/tmp /var/spool /media /home/.ecryptfs"

So it seems that my home dir is effectively invisible to the locate command because the dir is encrypted, this dramatically reduces the utility of the locate command, I wonder if find and grep suffer the same fate ?

Thanks,

Oisín.

cepheus11 09-10-2014 01:06 PM

A decrypted view of your home directory must be mounted somewhere while you work with it. You have to trigger updatedb to read that location, not the encrypted /home/.ecryptfs. I bet it is mounted as tmpfs filesystem, or as "fuse.<something>". Something which is ignored by updatedb because of PRUNEFS setting.

What does the command return:

Code:

mount
?

keefaz 09-10-2014 01:33 PM

Quote:

Originally Posted by Oisin (Post 5235703)
Indeed, I didn't know where to find updatedb.conf but upon inspecting it I see:

PRUNEPATHS="/tmp /var/spool /media /home/.ecryptfs"

So it seems that my home dir is effectively invisible to the locate command because the dir is encrypted, this dramatically reduces the utility of the locate command, I wonder if find and grep suffer the same fate ?

Thanks,

Oisín.

You can always remove /home/.ecryptfs from PRUNEPATHS in updatedb.conf, save it, then updatedb and try locate a file in your home directory
find and grep don't use /etc/updatedb.conf


All times are GMT -5. The time now is 03:22 AM.