Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm a bit new to unix/linux environment, but I have a small problem.

I'm using "locate" to find the path of a file I need, it gives me the path for it, but the file doesn't exist in that path, like that:

locate test1.txt

/home/user/test files/text1.txt
/home/user/test1.txt~

"test files" directory is where I was keeping the file and I copied it to the home directory once but I deleted it, no idea what it keeps telling me there is still a tmp file for it.

it worth mentioning that I used the command:

locate test1.txt~ |xargs -n1 rm

to remove that tmp file, but maybe that what caused the problem. I tried to show hidden files, and check for temp files, didn't find it either.

any clue what happened?

share|improve this question

migrated from stackoverflow.com Nov 30 '12 at 10:35

This question came from our site for professional and enthusiast programmers.

6  
locate uses a database that is only updated periodically (e.g. every 24 hours) so it's quite possible for the database and reality to be out of sync. –  Paul R Nov 29 '12 at 21:54
    
For better results, use find instead of locate (personal opinion alert - locate is the result of some misguided "we need to do things the same way Microsoft does" thinking). –  twalberg Nov 29 '12 at 22:12
    
@twalberg locate dates from 1983. That is two years before the first windows version was released. –  terdon Dec 2 '12 at 16:30

2 Answers 2

Locate command does not searches the whole filesystem. It picks up from the db file . It may be /var/lib/mlocate.db or some other db file. If you want the 'locate' command to give updated information run the command 'updatedb' before running 'locate'.

This updatedb can be added into cron on daily or weekly basis based on convenience. But one problem is that the updetedb command takes little bit time to update the db. So it is better to go with find command. At the same time the find command also not good for whole file system. If you know in advance in some directory the corresponding file might exists,then you can search only in that directory using the find command.

Ex. find some_directory_name -name file_name.

For more information please refer the corresponding man pages. Happy Linuxing...

share|improve this answer

You can update the db, using sudo updatedb and then try running locate again for getting the correct output.

This is because the db is updated periodically and using the command sudo updatedb will force the database to get updated at that moment itself.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.