Linux命令:help

语法

help: help [-dms] [模式 ...]
显示内建命令的相关信息。

显示内建命令的简略信息。如果指定了 PATTERN 模式,给出所有匹配 PATTERN 模式的命令的详细帮助,否则打印一个帮助主题列表。

选项:
-d description。只打印每个主题的功能的简要描述。
-m 以man样式打印帮助。
-s short。只打印语法部分。

说明

一般我们常用的是help跟一个命令,其实help可以用pattern来打印多个命令的用法。用法分两部分,一个是语法,一个含义或功能说明。分别用-s和-d表示。

help help

 1 help: help [-dms] [pattern ...]
 2     Display information about builtin commands.
 3 
 4     Displays brief summaries of builtin commands.  If PATTERN is
 5     specified, gives detailed help on all commands matching PATTERN,
 6     otherwise the list of help topics is printed.
 7 
 8     Options:
 9       -d        output short description for each topic
10       -m        display usage in pseudo-manpage format
11       -s        output only a short usage synopsis for each topic matching
12         PATTERN
13 
14     Arguments:
15       PATTERN   Pattern specifiying a help topic
16 
17     Exit Status:
18     Returns success unless PATTERN is not found or an invalid option is given.

举例

以下均以cd为例。

只打印语法部分

1 [root@gm ~]# help -d cd
2 cd - Change the shell working directory.

只打印作用说明部分

1 [root@gm ~]# help -s cd
2 cd: cd [-L|[-P [-e]]] [dir]

模拟man样式打印

 1 [root@gm ~]# help -m cd
 2 NAME
 3     cd - Change the shell working directory.
 4 
 5 SYNOPSIS
 6     cd [-L|[-P [-e]]] [dir]
 7 
 8 DESCRIPTION
 9     Change the shell working directory.
10 
11     Change the current directory to DIR.  The default DIR is the value of the
12     HOME shell variable.
13 
14     The variable CDPATH defines the search path for the directory containing
15     DIR.  Alternative directory names in CDPATH are separated by a colon (:).
16     A null directory name is the same as the current directory.  If DIR begins
17     with a slash (/), then CDPATH is not used.
18 
19     If the directory is not found, and the shell option `cdable_vars' is set,
20     the word is assumed to be  a variable name.  If that variable has a value,
21     its value is used for DIR.
22 
23     Options:
24         -L      force symbolic links to be followed
25         -P      use the physical directory structure without following symbolic
26         links
27         -e      if the -P option is supplied, and the current working directory
28         cannot be determined successfully, exit with a non-zero status
29 
30     The default is to follow symbolic links, as if `-L' were specified.
31 
32     Exit Status:
33     Returns 0 if the directory is changed, and if $PWD is set successfully when
34     -P is used; non-zero otherwise.
35 
36 SEE ALSO
37     bash(1)
38 
39 IMPLEMENTATION
40     GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)
41     Copyright (C) 2011 Free Software Foundation, Inc.
42     License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

打印多个命令帮助。

1 [root@gm ~]# help -s read*
2 Shell commands matching keyword `read*'
3 
4 read: read [-ers] [-a array] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd] [name ...]
5 readarray: readarray [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
6 readonly: readonly [-aAf] [name[=value] ...] or readonly -p
本篇文章出自“国民时代”,转载请注明转载出处。
原文地址:https://www.cnblogs.com/ChinaGo/p/10661049.html