== DESCRIPTION
-*whereis* locates the binary, source and manual files for the specified command names. The supplied names are first stripped of leading pathname components. Prefixes of *s.* resulting from use of source code control are also dealt with. *whereis* then attempts to locate the desired program in the standard Linux places, and in the places specified by *$PATH* and *$MANPATH*.
+*whereis* locates the binary, source and manual files for the specified command names. The supplied names are *first stripped of leading pathname components*. Prefixes of *s.* resulting from use of source code control are also dealt with. *whereis* then attempts to locate the desired program in the standard Linux places, and in the places specified by *$PATH* and *$MANPATH*.
The search restrictions (options *-b*, *-m* and *-s*) are cumulative and apply to the subsequent _name_ patterns on the command line. Any new search restriction resets the search mask. For example,
*-l*::
Output the list of effective lookup paths that *whereis* is using. When none of *-B*, *-M*, or *-S* is specified, the option will output the hard-coded paths that the command was able to find on the system.
+*-g*::
+Interpret the next names as a *glob(7)* patterns. *whereis* always compares only filenames (aka basename) and never complete path. Using directory names in the pattern has no effect. Don’t forget that the shell interprets the pattern when specified on the command line without quotes. It’s necessary to use quotes for the _name_, for example:
+____
+ whereis -g 'find*'
+____
+
include::man-common/help-version.adoc[]
== FILE SEARCH PATHS
#include <string.h>
#include <ctype.h>
#include <assert.h>
+#ifdef HAVE_FNMATCH
+# include <fnmatch.h>
+#endif
#include "xalloc.h"
#include "nls.h"
#define UL_DEBUG_CURRENT_MASK UL_DEBUG_MASK(whereis)
#include "debugobj.h"
-static char uflag = 0;
+static char uflag;
+static char use_glob;
/* supported types */
enum {
fputs(_(" -S <dirs> define sources lookup path\n"), out);
fputs(_(" -f terminate <dirs> argument list\n"), out);
fputs(_(" -u search for unusual entries\n"), out);
+ fputs(_(" -g interpret name as glob (pathnames pattern)\n"), out);
fputs(_(" -l output effective lookup paths\n"), out);
fputs(USAGE_SEPARATOR, out);
static int filename_equal(const char *cp, const char *dp, int type)
{
- int i = strlen(dp);
+ size_t i;
DBG(SEARCH, ul_debug("compare '%s' and '%s'", cp, dp));
+#ifdef HAVE_FNMATCH
+ if (use_glob)
+ return fnmatch(cp, dp, 0) == 0;
+#endif
if (type & SRC_DIR &&
dp[0] == 's' && dp[1] == '.' && filename_equal(cp, dp + 2, type))
return 1;
+
+ i = strlen(dp);
+
if (type & MAN_DIR) {
if (i > 1 && !strcmp(dp + i - 2, ".Z"))
i -= 2;
case 'l':
list_dirlist(ls);
break;
+ case 'g':
+ use_glob = 1;
+ break;
case 'V':
print_version(EXIT_SUCCESS);