# whereis results are cached?



## freethread (Sep 3, 2014)

Usually I use `whereis` command to check if a program is installed. I want to find if java is installed, there are other methods to check installed programs, but I executed `# whereis java`. The result was

```
java: /usr/ports/archivers/unzip/work/stage/usr/local/share/java
```
Ok, my /usr/ports directory is a bit dirty. To clean compile failures I then executed `# rm -rf /usr/ports/*/*/work`. Now I re-execute the `whereis` command:

```
# whereis java
java: /usr/ports/archivers/unzip/work/stage/usr/local/share/java
```
Same result. So go to check if the file/directory exists.

```
# ls /usr/ports/archivers/unzip
total 16
-rw-r--r--  1 root  wheel  -  3.2k 2014.08.15 12:11 Makefile
-rw-r--r--  1 root  wheel  -  123B 2014.08.15 12:11 distinfo
drwxr-xr-x  2 root  wheel  -  512B 2014.08.18 01:11 files
-rw-r--r--  1 root  wheel  -  1.0k 2014.01.22 16:44 pkg-descr
```
The work directory does not exist, so the only thing I can say is that the `whereis` result is cached somewhere. In the manual page there is nothing about cached results or flags acting on it, what is wrong?


----------



## kpa (Sep 3, 2014)

Some of the results are cached because they come from locate(1) that uses its own index database for quick results. If you run whereis(1) with the -x option it shouldn't try to use locate(1) after being unsuccesful at locating the requested file by other methods.


```
-x      Do not use “expensive” tools when searching for source directo‐
         ries.  Normally, after unsuccessfully searching all the first-
         level subdirectories of the source directory list, whereis will
         ask locate(1) to find the entry on its behalf.  Since this can
         take much longer, it can be turned off with -x
```


----------



## talsamon (Sep 3, 2014)

```
man whereis
...
-a      Report all matches instead of only the first of each requested
             type.

-b      Search for binaries.

....
```

whereis without parameter looks for the first entry in the database. If you run `portsclean -C` and `/etc/periodic/weekly/310.locate`- you got another entry (as first).


----------



## freethread (Sep 3, 2014)

Ok, many thanks @kpa and @talsamom. I know about the -a and -b flags, I use them when needed. What surprised me was the fact I had some uncleaned port work directory and the after cleaning them, `whereis` still report the deleted directories. Thank you both again.


----------

