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

如何在Linux系统上获取命令的帮助信息

2016-12-11 13:01 736 查看
在Linux系统中,获取命令帮助信息分为内部命令帮助获取和外部命令帮助两种;使用help命令用于显示shell内部命令的帮助信息;help命令只能显示shell内部的命令帮助信息。而对于外部命令的帮助信息只能使用man或者info命令查看。

内部命令帮助获取:

使用内建命令help+命令即可获取命令格式:# help COMMAND
例如使用 help cd 可以获得命令的cd命令的使用格式,详细功用描述,作用法则,常用选项,退出状态码等相关信息。

示例:
[root@localhost etc]# help cdcd: cd [-L|[-P [-e]]] [dir] Change the shellworking directory. Change the currentdirectory to DIR. The default DIR is thevalue of the HOME shell variable. The variable CDPATHdefines the search path for the directory containing DIR. Alternative directory names in CDPATH areseparated by a colon (:). A null directory nameis the same as the current directory. IfDIR begins with a slash (/), thenCDPATH is not used. If the directory isnot found, and the shell option `cdable_vars' is set, the word is assumed tobe a variable name. If that variable has a value, its value is used forDIR. Options: -L force symbolic links to be followed -P use the physical directory structurewithout following symbolic links -e if the -P option is supplied, and thecurrent working directory cannot be determined successfully, exit witha non-zero status The default is tofollow symbolic links, as if `-L' were specified. Exit Status: Returns 0 if thedirectory is changed, and if $PWD is set successfully when -P is used; non-zerootherwise. 如何判定命令是否为shell内部命令,可以使用type+命令来查看示例:[root@localhost etc]# type cdcd 是 shell 内嵌[root@localhost etc]# type catcat 是/usr/bin/cat从结果中可以清楚的看到cd是shell的内嵌命令,cat是外部命令。 外部命令帮助获取:(1) # COMMAND --help示例:
[root@localhost etc]# cat --help用法:cat [选项]... [文件]...将[文件]或标准输入组合输出到标准输出。 -A, --show-all 等于-vET -b,--number-nonblank 对非空输出行编号 -e 等于-vE -E, --show-ends 在每行结束处显示"$" -n, --number 对输出的所有行编号 -s, --squeeze-blank 不输出多行空行 -t 与-vT 等价 -T, --show-tabs 将跳格字符显示为^I -u (被忽略) -v,--show-nonprinting 使用^ 和M- 引用,除了LFD和 TAB 之外 --help 显示此帮助信息并退出 --version 显示版本信息并退出 如果没有指定文件,或者文件为"-",则从标准输入读取。 示例: cat f - g 先输出f 的内容,然后输出标准输入的内容,最后输出g 的内容。 cat 将标准输入的内容复制到标准输出。 GNU coreutils online help:<http://www.gnu.org/software/coreutils/>请向<http://translationproject.org/team/zh_CN.html>报告cat 的翻译错误要获取完整文档,请运行:info coreutils 'cat invocation' (2) # man COMMANDman命令是Linux下的帮助指令,通过man指令可以查看Linux中的指令帮助、配置文件帮助和编程帮助等信息。 man手册页章节的命名规则man1: 用户命令;man2: 系统调用;man3: C库调用; man4: 设备文件及特殊文件;man5: 配置文件格式;man6: 游戏;man7: 杂项;man8: 管理类的命令;man9:内核。 命令格式:# man COMMAND
示例:
[root@localhost etc]# man lsLS(1) UserCommands LS(1) NAME ls - list directorycontents SYNOPSIS ls [OPTION]...[FILE]... DESCRIPTION List information about the FILEs (the current directory bydefault). Sort entriesalphabetically if none of -cftuvSUX nor --sort is specified. Mandatory argumentsto long options are mandatory for short options too. -a, --all do notignore entries starting with . -A, --almost-all do not listimplied . and .. --author with -l,print the author of each file -b, --escape man手册中段落的说明:NAME :手册页名称SYNOPSIS:语法DESCRIPITION:描述RETURN VALUE:返回值EXIT STATUS:命令返回码ERROR HANDLING:错误处理ERRORS:错误代码OPTIONS:选项USAGE:用法EXAMPLES:示例FILES :相关文件ENVIRONMENT:相关环境变量DIAGNOSTICS:诊断SECURITY:安全性CONFORMING TO:兼容性NOTES:备注BUGS:BugAUTHOR:作者SEE ALSO:参阅 man手册阅读中的操作方法:Space,Ctrl+V,Ctrl+f, Ctrl+F: 向文件尾翻屏;b, Ctrl+B:向文件首部翻屏;d, Ctrl+D:向文件尾部翻半屏;u, Ctrl+U:向文件首部翻半屏;回车键,Ctrl+N, e, Ctrl+E , j , Ctrl+J: 向文件尾部翻一行;y ,Ctrl+Y,Ctrl+P ,k, Ctrl+K:向文件首部翻一行;q: 退出;键入数字按下回车跳转至第指定行(例如:键入15按下回车跳转至第15行)键入1G回到文件首部键入G回到文件尾部文本搜索/KEYWORD:以KEYWORD指定的字符串为关键字,从当前位置向文件尾部搜索;不区分字符大小写;在搜索结果中使用n: 下一个N:上一个以KEYWORD指定的字符串为关键字,从当前位置向文件首部搜索;不区分字符大小写;在搜索结果中使用n: 跟搜索命令同方向,下一个; N:跟搜索命令反方向,上一个 (3) # info COMMAND查看命令的info帮助文档
示例:
[root@localhost etc]# info cat File: coreutils.info, Node:cat invocation, Next: tacinvocation, Up: Output of enti\re files 3.1 'cat': Concatenate and write files====================================== 'cat' copies each FILE ('-' means standard input), or standardinput ifnone are given, to standard output. Synopsis: cat [OPTION][FILE]... The program accepts thefollowing options. Also see *note Commonoptions::. '-A''--show-all' Equivalent to '-vET'. '-b''--number-nonblank' Number all nonemptyoutput lines, starting with 1. '-e'--zz-Info: (coreutils.info.gz)cat invocation, 73 lines--Top----------------------------Welcome to Info version 5.1. Type h for help, m for menu item. info的常用快捷键:?键:它就会显示info的常用快捷键;N键:显示(相对于本节点的)下一节点的文档内容;P键:显示(相对于本节点的)前一节点的文档内容;U键:进入当前命令所在的主题;M键:敲M键后输入命令的名称就可以查看该命令的帮助文档了;G键:敲G键后输入主题名称,进入该主题。 L键:回到上一个访问的页面;SPACE键:向前滚动一页;BACKUP或DEL键:向后滚动一页;Q:退出info。 (4) 程序自身的帮助文档文档位置:/usr/share/doc/COMMAND-VERSION
示例:
[root@localhost etc]# cd /usr/share/doc/[root@localhost doc]# lsabattis-cantarell-fonts-0.0.16 libraw1394-2.1.0abrt-2.1.11 librdmacm-1.0.21abrt-dbus-2.1.11 libref_array-0.1.5libpng-1.5.13 yum-plugin-fastestmirror-1.1.31libproxy-0.4.11 yum-utils-1.1.31libpurple-2.10.7 zenity-3.8.0libpwquality-1.2.3 zip-3.0libqmi-1.6.0 zlib-1.2.7[root@localhost doc]# cd zip-3.0[root@localhost zip-3.0]# lsalgorith.txt CHANGES LICENSE README README.CR TODO WHATSNEW WHERE[root@localhost zip-3.0]# cat README (5) 程序官方发行的帮助文档。(6) Linux发行版官方站点发布的文档(7) Google(8) slideshare网站http://www.slideshare.net/

备注:本文中的全部示例操作位基于VMware Workstation 12 Pro虚拟机下的CentOS 7操作系统中完成。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息