Thursday, September 20, 2007

Searching using whereis linux command

Now, another simple linux command for locating binary, source and manual pages using whereis.

From recent linux 'which' blog entry, here is another way to find and locate the location and full path of a particular binary, man pages and sources of a given program argument. Whereis locates the binary from the standard linux binary locations.

Whereis man description says:
whereis locates source/binary and manuals sections for specified files. The supplied names are first stripped of leading pathname components and any (single) trailing extension of the form .ext, for example, .c. Prefixes of s. resulting from use of source code control are also dealt with. whereis then attempts to locate the desired program in a list of standard Linux places.



Whereis Usage and Explanation:
~~~~~~~~~~~~~~

# whereis cat
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cat: /bin/cat /usr/share/man/man1p/cat.1p.gz /usr/share/man/man1/cat.1.gz
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

From the above result, Whereis shows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a. cat binary location is /bin
b. cat man and source pages are currently located in
/usr/share/man/man1p/c
/usr/share/man/man1/c
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


More Whereis Usage and Examples:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To locate a binary or executables location only using whereis
# whereis -b cat
~~~~~~~~~~~~~~~~~~~~
cat: /bin/cat
~~~~~~~~~~~~~~~~~~~~

To locate and search from manual pages or section of a binary using whereis from terminal
# whereis -m cat
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cat: /usr/share/man/man1p/cat.1p.gz /usr/share/man/man1/cat.1.gz
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To limit the place where whereis would search location from
# whereis -B /sbin -b cat

which shows no result since we know that binary cat is located from /bin folder location and not /sbin which was specified above.

Now, here's another whereis example application

# cd /tmp
# touch cat
# ch700 cat
# whereis -B /tmp -b cat
result:
~~~~~~~~~~~~~~~~~
cat: /tmp/cat
~~~~~~~~~~~~~~~~~

# whereis abc123
# whereis cat echo

# whereis whereis
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
whereis: /usr/bin/whereis /usr/share/man/man1/whereis.1.gz
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

HTH

0 comments:

Sign up for PayPal and start accepting credit card payments instantly.
ILoveTux - howtos and news | About | Contact | TOS | Policy