您的位置:首页 > 运维架构 > Linux

Linux基础-获取命令帮助与命令的查找(1)

2014-01-04 16:01 756 查看
如何获取命令帮助

命令分类:内置命令:bash内置的命令;外部命令:非bash所提供的命令;

内置命令:help command

外部命令: 1、manual:使用手册:man command; 2、info:信息页:info command (支持超链接,页间跳转); 3、简要使用帮助: command --help; 4、官方文档; 5、额外的文档:README、INSTALL、ChangeLog 命令自带的官方文档存放路径:/usr/share/doc/command-version; 6、发行版官方文档:http://www.redhat.com/docs/ 系统安装文档、部署指南、集群使用手册等。7、googleman手册:分章节(分类别)程序员的很多工作都是在文档开发。写文档、写备注、注释是程序的基本工。

程序的配置文件用于定义程序的工作特性:这种特性是可选的,可以启、不启用,通过调整配置文件某个参数的值来实现。

man手册,不仅包含程序自身的说明,还包含配置文件语法、格式的说明 对于不同类别的命令或配置等的手册位于不同的章节中; 1:用户命令; 2:系统调用的函数与工具说明; 3:库调用的说明,函数与函数库; 4:设备文件的说明; 5:文件格式或配置文件; 6:游戏; 7:杂项(惯例或协议); 8:管理类命令; 9:与kernel有关的文件。 操作键: 空格键: 向后翻一屏; b键: 向前翻一屏 回车键: 向后翻一行; k键: 向前翻一行; Ctrl+d: 向后翻半屏; Ctrl+u: 向前翻半屏; G键: 跳转至文件尾; 1G键: 跳转至文件首; q键: 退出;

文件查找:/keyword: 从当前光标所在行开始,向文件尾部查找;?keyword:向文件首部查找;n键: 跟的那个查找命令相同方向的下一个匹配;N键:跟的那个查找命令相反方向的下一个匹配;

命令查找

man命令man -f command-f:相当于whatis命令,获得更多command的相关信息; man -k command-k:相当于apropos命令,利用关键字将说明文件里面只要含有“command”的那个字(不一定是完整字符串),并将它取出来;man n commandn:“n”代表数字,表示查询第n章节的command说明文件。man 7 command
man -f [命令或者数据] == whatis [命令或者数据]man -k [命令或者数据] == apropos [命令或者数据]注意:whatis与apropos两个特殊命令要能使用,必须先使用“makewhatis”创建数据库whatis。

[root@www ~]# man -f man
man (1) - format and display the on-line manual pages
man (1p) - display system documentation
man (7) - macros to format man pages
man [manpath] (1) - format and display the on-line manual pages
man-pages (7) - conventions for writing Linux man pages
man.config [man] (5) - configuration data for man
************************************************************
[root@www ~]# whatis man
man                  (1)  - format and display the on-line manual pages
man                  (1p)  - display system documentation
man                  (7)  - macros to format man pages
man [manpath]        (1)  - format and display the on-line manual pages
man-pages            (7)  - conventions for writing Linux man pages
man.config [man]     (5)  - configuration data for man


[root@www ~]# man -k man
. [builtins] (1) - bash built-in commands, see bash(1)
/etc/hosts.equiv [hosts] (5) - list of hosts and users that are granted trusted r command access to your system
: [builtins] (1) - bash built-in commands, see bash(1)
App::Prove (3pm) - Implements the prove command
..................省略....................................
[root@www ~]# apropos man
. [builtins]         (1)  - bash built-in commands, see bash(1)
/etc/hosts.equiv [hosts] (5)  - list of hosts and users that are granted trusted r command access to your system
: [builtins]         (1)  - bash built-in commands, see bash(1)
App::Prove           (3pm)  - Implements the prove command
..................省略....................................


which命令
查找“执行文件”which命令时根据PATH环境变量所规范的路径去查找“执行文件”的文件名,所以查找的命令都是外部命令。which -a command-a:将所有在PATH目录中的找到的所有命令全部列出来(包括命令别名)。command:完整的文件名;

[root@www ~]# which -a ls
alias ls='ls --color=auto'
/bin/ls
***************************************************************
[root@www ~]# which cd
/usr/bin/which: no cd in (/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
#因为cd是bash内置命令,所以报错!


type命令通过type命令可以知道命令是否为bash的内置命令,如果后接的名称不能以执行状态被找到,该名称则不会被显示出来。type命令主要是找出“执行文件”而不是一般文件名,类似which命令的用途。
type name显示name是外部命令还是内置命令;

[root@www ~]# type cd
cd is a shell builtin
[root@www ~]# type ls
ls is aliased to `ls --color=auto'
[root@www ~]# type man
man is /usr/bin/man


type [-tpa] name参数:-t:当加入-t参数时,type会将name以下面这些字眼显示出它的意义: file: 表示为外部命令; alias : 表示该命令为命令别名所设置的名称; builtin:表示该命令为bash内置的命令功能。-p:如果后面接的name为外部命令时,才会显示出完整的文件名;-a:会由PATH变量定义的路径中,将所有含name的命令都列出来,包含alias
[root@www ~]# type man
man is /usr/bin/man
[root@www ~]# type -t man
file
[root@www ~]# type -t ls
alias
[root@www ~]# type -t cd
builtin


[root@www ~]# type -p cd    #如果命令为内置命令则不显示
[root@www ~]# type -p ls    #如果命令为命令别名也不显示
[root@www ~]# type -p man
/usr/bin/man


[root@www ~]# type -a man
man is /usr/bin/man
[root@www ~]# type -a ls
ls is aliased to `ls --color=auto'
ls is /bin/ls


help命令显示内置命令的帮助信息
[root@www ~]# help cd
cd: cd [-L|-P] [dir]
Change the shell working directory.

Change the current directory to DIR.  The default DIR is the value of the
HOME shell variable.

The variable CDPATH defines the search path for the directory containing
DIR.  Alternative directory names in CDPATH are separated by a colon (:).
..................省略....................................

help [-dms] command-d: 显示该命令的简短说明; -m:显示该命令的详细说明; -s: 简短的用法简介;command:可以是关键字,也可以是完整的命令名称。
[root@www ~]# help -d cd
cd - Change the shell working directory.
*********************分隔符***********************************
[root@www ~]# help -m cd
NAME
cd - Change the shell working directory.
SYNOPSIS
cd [-L|-P] [dir]
DESCRIPTION
Change the shell working directory.

Change the current directory to DIR.  The default DIR is the value of the
HOME shell variable.
..................省略....................................
*********************分隔符***********************************
[root@www ~]# help -s cd
cd: cd [-L|-P] [dir]


history命令参数:history n:显示n-1个历史命令;

[root@www ~]# history 5
550  clear
551  help cd
552  help -d cd
553  help -m cd
554  history 5#刚执行的history 5也算一个历史命令,所以是显示n-1个

-c:清除所有历史命令;
-d n:“n”代表数字, 删除第n条命令。

history [-raw] histfiles-a:将新增的history命令加入histfiles中,若没有指定histfiles,则默认写入~/.bash_history;-r:将histfiles的内容导入目前这个shell的history记忆中;-w:将目前的history记忆内容写入history中,手动保存历史命令,追加保存历史命令;!n:执行第n条历史命令;!-n:执行倒数第n条历史命令;!command:从最近的历史命令向前搜寻命令串以“command”开头的那个命令,并执行;!!:执行上一个命令上下箭头可以翻动历史命令 正常logout的历史命令列表会保存至~/.bash_history文件中,可以在环境变量HISTFILE定义历史命令列表的保存位置。history的命令历史由两部分组成: 1、~/.bash_history:保存的是此前用户退出后保存至用户的配置文件当中的命令历史 2、当前缓冲区中的命令历史;
与命令历史相关的环境变量:HISTFILE变量定义默认历史命令记录的放置文件(隐藏文件);HISTFILESIZE变量定义保存的(与上个变量有关)的文件命令的最大记录条数;HISTSIZE变量定义目前环境下记录的历史命令最大条数(在内存缓冲区中能保存的命令历史的条目)。

command命令执行一个简单的命令或显示该命令的信息。
command [-Vv] command -v:打印命令的类型(内置命令或外部命令);-V:打印命令的详细信息;command command显示command命令的简要用法。

[root@www ~]# command -v cd
cd
[root@www ~]# command -v ls
alias ls='ls --color=auto'
[root@www ~]# command -v man
/usr/bin/man

[root@www ~]# command -V cd
cd is a shell builtin
[root@www ~]# command -V ls
ls is aliased to `ls --color=auto'
[root@www ~]# command -V man
man is hashed (/usr/bin/man)


本文出自 “三思” 博客,请务必保留此出处http://szyangxiao.blog.51cto.com/8022664/1348444
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: