12 Linux Which Command, Whatis Command, Whereis Command Examples
This Linux tutorial will explain the three “W” commands. The three “W”s are whatis, whereis and which commands. You already know how to use find
command to efficiently fo find a file.
Now, these three W commands will help you to locate more stuff from Linux command line.
I. Linux whatis Command
Whatis command is helpful to get brief information about Linux commands or functions. Whatis command displays man page single line description for command that matches string passed as a command line argument to whatis command. Whatis command searches for string
in its index databases which is maintained by mandb program. Whatis command picks short description of NAME section of man page of command that matches to input given to the whatis command.
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]
For example, here is the output of whatis command, when it is run without any option.
$ whatis write
write (1) - send a message to another user
write (2) - write to a file descriptor
It displays brief information about “write” from man pages.
1. Get information from specific sections of man pages using -s option
If we want to get Linux command information from specific section of man pages, then we can provide sections list using “-s or —sections or –section” option. It will restrict whatis command to display brief information from specified man page section only.
$ 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
It displays open command and function brief information from man page sections 1 and 2.
$ whatis -s "2" open
open (2) - open and possibly create a file or device
It displays open function brief information from man page section 2.
2. Search information through wild-cards using -w option
If we want to search Linux commands or functions information using wild card, then whatis command gives “-w or –wildcard” option. It will make your search specific as per user’s need.
$ whatis -w 'ab*'
abort (3) - cause abnormal process termination
abs (3) - compute the absolute value of an integer
It displays brief information of Linux commands or functions which start from “ab”.
$ whatis -w 'ab?'
abs (3) - compute the absolute value of an integer
It displays brief information of Linux commands or functions which start from “ab” and followed by any single character.
3. Search information through regular expressions using -r option
If we want to search Linux commands or functions information using regular expressions, then whatis command gives “-r or –regex” option. It will give flexibility to customize your search for Linux commands or functions throughout the Linux system.
$ whatis -r '^ab'
abort (3) - cause abnormal process termination
abs (3) - compute the absolute value of an integer
It displays brief information of Linux commands or functions which start from “ab”.
$ 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
It displays brief information of Linux commands or functions which ends with “ab”.
4. Disable trimmed output using -l option
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” option 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...
It displays trimmed output of brief information of Linux command.
$ 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)
It displays complete output of brief information of Linux command.
5. Restrict search up to specified path using -M option
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
It displays brief information of Linux hexdump command from man pages available at path /usr/share/man.
$ whatis -M /usr/man hexdump
hexdump: nothing appropriate.
It could not find brief information of Linux hexdump command from specified path /usr/man.
II. Linux whereis Command
Whereis command is helpful to locate binary, source and manual pages of commands in the Linux system. It is very simple utility and provides several options
which are given below with examples.
Syntax:
$ whereis [-options]
For example, whereis command is run without any option.
$ whereis open
open: /bin/open /usr/share/man/man1/open.1.gz /usr/share/man/man2/open.2.gz
It locates binary, source and man pages of “open” command and here it displayed paths where binary, man pages of open command is available in the system.
6. Locate binaries using -b option
If we want to locate binary of Linux command, use “-b” option.
$ whereis -b whereis
whereis: /usr/bin/whereis /usr/bin/X11/whereis
It locates binary of “whereis” command and displays paths where binary of command is available in the system.
7. Locate man pages for a command using -m option
If we want to locate man page of Linux command, use “-m” option.
$ whereis -m whereis
whereis: /usr/share/man/man1/whereis.1.gz
It locates man page of “whereis” command and displays path where man page of command is available in the system.
8. Locate source of a command using -s option
If we want to locate source of Linux command, use “-s” option.
$ whereis -s whereis
whereis:
It locates source of “whereis” command, but source of “whereis” command does not exist in the system, so it did not display path for source of command in the system.
9. Locate unusual entries using -u option
This option is something 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 (i.e. wcgrep) man page does not exist in the system. Whereis command with options “-m and -u” locates for the commands in the system whose man page does not exist.
$ whereis -m -u grep
$
Here, whereis command with same options is applied on “grep” command whose man page exists in the system, so whereis returned nothing and exits normally.
10. Locate binaries in a specified path using -B option
If user wants to search for binary and wants to limit the scope of search for whereis command up to specified path, then use “-B” option.
$ whereis -B /bin -f for_loop
for_loop: /bin/for_loop
It locates binary of “for_loop” user program from path “/bin”.
$ whereis -B /usr -f open
open: /usr/share/man/man1/open.1.gz /usr/share/man/man2/open.2.gz
If open command’s binary is not found at specified path, then it is not shown but whereis command by default searches for other types (i.e. man page and source) of specified command (i.e. open) and displays them if found.
11. Locate man pages with limited scope using -M option
If user wants to search for man pages and wants to limit the scope of search for whereis command up to specified path, then 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
Here, it is observed that whereis command is displaying man page of “open” command which is available in specified path only. But, whereis command by default searches for other types (i.e. binary and source) of specified command (i.e. open) and displays them
if found.
III. Linux which Command
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]
For example,
$ which ls gdb open grep
/bin/ls
/usr/bin/gdb
/bin/open
/bin/grep
It locates command names – “ls”, “gdb”, “open” and “grep” specified as arguments to “which” command and displays paths of each executable where it exists in the system.
12. Display all the paths using -a option
“which” command gives option “-a” that displays all paths of executable matching to argument.
$ which echo
/usr/sbin/echo
Above will search display the executable “echo” from all paths set in $PATH environment variable and displays the first path where echo executable is found. It may be case that executable is placed at other paths of $PATH environment variable as well. To get
all paths where executable is present in the system, “-a” option can be used.
$ which -a echo
/usr/sbin/echo
/bin/echo
12 Linux Which Command, Whatis Command, Whereis Command Examples的更多相关文章
- 设计模式 - 命令模式(command pattern) 宏命令(macro command) 具体解释
命令模式(command pattern) 宏命令(macro command) 具体解释 本文地址: http://blog.csdn.net/caroline_wendy 參考: 命名模式(撤销) ...
- linux 文件查找,which,whereis,locate,find
linux 文件查找,which,whereis,locate,find 一:which 主要用于查找可执行命令的所在位置: 如图,查找命令 ls的目录: 二:whereis 主要用于查找命令的帮助文 ...
- [转帖]Linux教程(12)- linux输入输出重定向
Linux教程(12)- linux输入输出重定向 2018-08-21 22:57:02 钱婷婷 阅读数 49更多 分类专栏: Linux教程与操作 Linux教程与使用 版权声明:本文为博主原 ...
- linux - man 提示:-bash: man: command not found
在执行man命令时,提示:-bash: man: command not found 原因1:没有配置path环境 解决:vi /etc/profile JAVA_HOME=/usr/java/jdk ...
- Linux Oracle bash: “sqlplus / as sysdba”: command not found 解决方法
bash: sqlplus: command not found 解决方法 注:本文来源于 < bash: sqlplus: command not found 解决方法 > 1: ...
- linux下报错bash: service: command not found
在linux下操作的时候经常会遇到,bash: service: command not found这个错误,以前在网上找了,照着弄了,也没细看原因,今天又碰到这个问题,就顺便研究一下. 1.通常这种 ...
- 解决 linux 下安装 node 报: command not found
注意:有时安装成功后,需要关闭xshell,重新启动.nvm才会生效. 1. 在 linux 下安装 node 提示 -bash: node: command not found. 2. 这种情况可 ...
- 【linux报错】-bash: xhost: command not found
参考自:http://blog.csdn.net/csdnones/article/details/51513163,感谢原作者解决了我的问题. 执行xhost +,报以下错误,原因是因未没有安装相关 ...
- Linux改动/etc/profile配置错误command is not found自救方法
我的CSDN博客地址: http://blog.csdn.net/caicongyang 博主之前在改动了/etc/profile配置文件方法后,导致bash命令无法用 运行ls命令结果例如以下: - ...
随机推荐
- 【npm】伙计,给我来一杯package.json!不加糖
前言:夜深了,我熬了一锅热气腾腾的package.json,给大家端上来,希望大家喜欢 json和JS对象的区别 package.json,顾名思义,它是一个json文件,而不能写入JS对象. 所以我 ...
- 阿里巴巴Java开发规约及插件安装
[上海尚学堂编辑整理]10.14日,阿里巴巴在杭州云栖大会上,正式发布了由阿里巴巴 P3C 项目组,经过 近一年的持续研发,正式发布众所期待的 <阿里巴巴 Java 开发规约>的扫描插件. ...
- 京东购物车的 Java 架构实现及原理!
今天来写一下关于购物车的东西, 这里首先抛出四个问题: 1)用户没登陆用户名和密码,添加商品, 关闭浏览器再打开后 不登录用户名和密码 问:购物车商品还在吗? 2)用户登陆了用户名密码,添加商品,关闭 ...
- linux下如何把php升级到5.6
1: 进入终端后查看php版本 php -v 输出可能如下: PHP (cli) (built: Nov ::) Copyright (c) - The PHP Group Zend Engine v ...
- tensorflow 1.0 学习:用CNN进行图像分类
tensorflow升级到1.0之后,增加了一些高级模块: 如tf.layers, tf.metrics, 和tf.losses,使得代码稍微有些简化. 任务:花卉分类 版本:tensorflow 1 ...
- Ocelot简易教程(一)之Ocelot是什么
作者:依乐祝 原文地址:https://www.cnblogs.com/yilezhu/p/9557375.html Ocelot简易教程目录 Ocelot简易教程(一)之Ocelot是什么 Ocel ...
- python args kwargs 传递参数的区别
先来看个例子: def foo(*args, **kwargs): print 'args = ', args print 'kwargs = ', kwargs print '----------- ...
- Docker中运行nginx并挂载本地目录到镜像中
1.1 从hup上pull镜像1.2 创建将要挂载的目录1.3 先要有配置文件才能启动容器1.3.1 vim /data/nginx/conf/nginx.conf1.3.2 vim /data/ng ...
- windows系统下发布python模块到pypi
1. 在pypi.python.org网站注册一个用户,记住用户名和密码. 2. 编写需要上传模块的源代码,文件名为:skyersfirstpythonmodule.py 3. 新建文件夹,名称为sk ...
- python使用多线程
threading 模块支持守护线程, 其工作方式是:守护线程一般是一个等待客户端请求服务的服务器. 如果把一个线程设置为守护线程,进程退出时不需要等待这个线程执行完成. 如果主线程准备退出时,不需要 ...