Never Ending Security

It starts all here

whatis Command Examples for Linux

whatis Command Examples

Whatis command is very helpful when you want to get a brief information about Linux command or function. Whatis command displays man page single line description for command that matches string passed as a command line argument. It searches for a string in its index databases which is maintained by mandb program.

Whatis provides several command line options to help user in getting brief information of specific Linux commands as per their need or interest.

Syntax:

$ whatis [-options]

Example

$ whatis write
write (1)            - send a message to another user
write (2)            - write to a file descriptor

Get information from specific sections of man pages

If you want to get command information from a specific section of man page, then you should use “-s or —sections or –section” switch.

$ whatis -s "1","2" open
open (1)             - start a program on a new virtual terminal (VT).
open (2)             - open and possibly create a file or device

$ whatis -s "2" open
open (2)             - open and possibly create a file or device

Search using wild-cards

If you want you can perform your search using wild card, giving “-w or –wildcard” switch.

$ whatis -w 'ab*' 
abort (3)    - cause abnormal process termination 
abs (3)      - compute the absolute value of an integer

$ whatis -w 'ab?'
abs (3)              - compute the absolute value of an integer

Search using regular expressions

Regular expression search can be performed with “-r or –regex” switch.

$ whatis -r '^ab'
abort (3)            - cause abnormal process termination
abs (3)              - compute the absolute value of an integer

$ whatis -r 'ab$'
anacrontab (5)       - configuration file for anacron
baobab (1)           - A graphical tool to analyse disk usage
crontab (1)          - maintain crontab files for individual users (Vixie Cron)
crontab (5)          - tables for driving cron
fstab (5)            - static information about the filesystems
inittab (5)          - init daemon configuration
swab (3)             - swap adjacent bytes
tc-stab (8)          - Generic size table manipulations

Disable trimmed output

Generally whatis command trims long output of Linux commands or functions information to avoid “Not good” output display on terminal that is going beyond screen. To allow whatis command to show complete output on screen, “-l or –long” switch can be used.

$ whatis ssh-import-id
ssh-import-id (1)    - retrieve one or more public keys from a public keyserver (Launchpad.net by default) and append them to the current user's authorized_keys file (or some other specifie...

$ whatis -l ssh-import-id
ssh-import-id (1)    - retrieve one or more public keys from a public keyserver (Launchpad.net by default) and append them to the current user's authorized_keys file (or some other specified file)

Restrict search up to specified path

By default, whatis command uses $MANPATH environment variable. But whatis provides “-M or –manpath” option to restrict search up to specified path of man pages.

$ whatis -M /usr/share/man hexdump
hexdump (1)          - ASCII, decimal, hexadecimal, octal dump

$ whatis -M /usr/man hexdump
hexdump: nothing appropriate.

whereis Command Examples

Whereis command can be used to locate binary, source and manual page in the Linux system. It is very simple utility and provides several options:

Syntax:

$ whereis [-options]

Example

$ whereis open
open: /bin/open /usr/share/man/man1/open.1.gz /usr/share/man/man2/open.2.gz

Locate binaries

To locate binary, use “-b” switch.

$ whereis -b whereis
whereis: /usr/bin/whereis /usr/bin/X11/whereis

Locate man pages

To locate man page, use “-m” switch.

$ whereis -m whereis
whereis: /usr/share/man/man1/whereis.1.gz

Locate source

To locate source, use “-s” switch.

$ whereis -s whereis
whereis:

Locate unusual entries

This option is somewhat different that searches for unusual entries. These entries are those command whose source, binary or man page does not exist in the system as per options “[-bms]” specified along with “–u”.

$ whereis  -m  -u wcgrep
wcgrep:

It checks if specified command (wcgrep) man page does not exist in the system

Locate binaries in a specified path

If you need to search for binary in limited scope, use “-B” switch.

$ whereis -B /bin -f for_loop
for_loop: /bin/for_loop

$ whereis -B /usr -f open
open: /usr/share/man/man1/open.1.gz /usr/share/man/man2/open.2.gz

Locate man pages with limited scope

To search for man pages in limited scope, use “-M” option.

$ whereis -M /usr/share/man/man1 -f open
open: /bin/open /usr/share/man/man1/open.1.gz
$ whereis -M /usr/share/man/man2 -f open
open: /bin/open /usr/share/man/man2/open.2.gz
$ whereis -M /usr/share/man/man3 -f open
open: /bin/open

which Command Examples

Which command is very small and simple command to locate executables in the system. It allows user to pass several command names as arguments to get their paths in the system. “which” commands searches the path of executable in system paths set in $PATH environment variable.

Syntax:

$ which [-option]

Example,

$ which ls gdb open grep
/bin/ls
/usr/bin/gdb
/bin/open
/bin/grep

Display all paths

To get all paths use “-a” switch.

$ which -a  echo
/usr/sbin/echo
/bin/echo
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s