LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-10-2014, 08:29 AM   #1
Oisin
LQ Newbie
 
Registered: Apr 2005
Location: Dublin Ireland
Distribution: Ubuntu
Posts: 10

Rep: Reputation: 0
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.
 
Old 09-10-2014, 08:39 AM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
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?
 
Old 09-10-2014, 08:56 AM   #3
Oisin
LQ Newbie
 
Registered: Apr 2005
Location: Dublin Ireland
Distribution: Ubuntu
Posts: 10

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by keefaz View Post
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.
 
Old 09-10-2014, 08:59 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,801

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
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.
 
Old 09-10-2014, 09:53 AM   #5
Oisin
LQ Newbie
 
Registered: Apr 2005
Location: Dublin Ireland
Distribution: Ubuntu
Posts: 10

Original Poster
Rep: Reputation: 0
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.
 
Old 09-10-2014, 10:38 AM   #6
cepheus11
Member
 
Registered: Nov 2010
Location: Germany
Distribution: Gentoo
Posts: 286

Rep: Reputation: 91
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.
 
Old 09-10-2014, 10:41 AM   #7
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Maybe check /etc/updatedb.conf, as pan64 and cepheus11 suggested
 
Old 09-10-2014, 11:50 AM   #8
Oisin
LQ Newbie
 
Registered: Apr 2005
Location: Dublin Ireland
Distribution: Ubuntu
Posts: 10

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by keefaz View Post
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.
 
Old 09-10-2014, 12:06 PM   #9
cepheus11
Member
 
Registered: Nov 2010
Location: Germany
Distribution: Gentoo
Posts: 286

Rep: Reputation: 91
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
?
 
Old 09-10-2014, 12:33 PM   #10
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
Quote:
Originally Posted by Oisin View Post
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Squid forward_for appears to not work blackfish Linux - Server 4 01-10-2011 09:47 AM
Passwd command appears to work......but still can't log in. bbalzer Linux - General 1 02-23-2009 10:07 AM
cpan> locate -u Unknown shell command 'locate -u'. Type ? for help. sharad2005 Linux From Scratch 1 08-04-2006 12:40 AM
the command prompt always appears.... melinda_sayang Programming 5 01-09-2005 10:06 AM
Locate command does not work waffe Linux - General 2 09-26-2003 09:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration