LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Where whereis is searching (https://www.linuxquestions.org/questions/linux-general-1/where-whereis-is-searching-876396/)

Diamantis 04-21-2011 02:44 PM

Where whereis is searching
 
I am writing a script to install a program (a GUI interface) and would like to search if the required software is already installed. This made me think of the command whereis.

I was curious how the command whereis is working but didn't know where to search. Is it equivalent with a find at the most common locations?
thank you very much

jcalzare 04-21-2011 02:48 PM

whereis has a hard-coded path it searches for your search term. Similar to the way 'which' works, but does not use the $PATH environment variable, but rather a path determined by the distro.

From the man page:

whereis has a hard-coded path, so may not always find what you're looking for.

SL00b 04-21-2011 02:51 PM

Also from the man page:

"whereis then attempts to locate the desired program in a list of standard Linux places."

Diamantis 04-21-2011 02:54 PM

Quote:

Originally Posted by jcalzare (Post 4331924)
whereis has a hard-coded path it searches for your search term. Similar to the way 'which' works, but does not use the $PATH environment variable, but rather a path determined by the distro.

From the man page:

whereis has a hard-coded path, so may not always find what you're looking for.

Thanks!

So is there any other "standard" way to search for already installed software? I would like the GUI I am making to make sure the user has already installed the prerequisites.

jcalzare 04-21-2011 03:01 PM

Well if you have mlocate installed, you could do something like:

Code:

updatedb
locate binaryname

Obviously binaryname would be whatever software you're looking for. I guess this might not be the best solution because you'd have to make sure they have mlocate installed.. more dependencies.

Edit: You could also take the approach commonly used by configure scripts when compiling from source: Check in $PATH with something like 'which', if it's not there, tell the user they need to specify the location of the binary with flags like... --mysqldir=/var/lib/mysql

rob.rice 04-22-2011 06:23 PM

the find command is a very flexible file locater
you can set the search path and what find will do with the results of the search

rob.rice 04-22-2011 06:35 PM

Quote:

Originally Posted by jcalzare (Post 4331935)
Well if you have mlocate installed, you could do something like:

Code:

updatedb
locate binaryname

Obviously binaryname would be whatever software you're looking for. I guess this might not be the best solution because you'd have to make sure they have mlocate installed.. more dependencies.

Edit: You could also take the approach commonly used by configure scripts when compiling from source: Check in $PATH with something like 'which', if it's not there, tell the user they need to specify the location of the binary with flags like... --mysqldir=/var/lib/mysql

2 problems with your suggestion

1 updatedb reads every directory and every file name accessible on a file system to build the data base this is extremely slow
on a fresh slackware install this can tack up to half an hour depending on the speed of the hard drive
2 locate is extremely lose on what it considers a match a file name can be 3 letters off from the searched for spelling and still be included in the search results


All times are GMT -5. The time now is 05:52 PM.