Linux 获取命令帮助信息

点击访问 Linux 命令大全 >>

本文将介绍怎样在 Linux 中获取某个命令的帮助信息,因为我们不可能将每个命令的所有选项都能记住。因此,有时需要用到时通过查看命令的帮助信息,为我们提供参考。

whatis 获取命令基础信息

whatis 命令用于获取指定命令的主要功能。使用该指令可以快速了解某个命令的作用,例如:

[root@localhost ~]# whatis ifconfig
ifconfig (8)         - configure a network interface

上面例子中,我们使用 whatis 查看 ifconfig 命令的作用。

实际上,whatis 命令等同于使用 man -f 命令。例如:

[root@localhost ~]# man -f ifconfig
ifconfig (8)         - configure a network interface

apropos 获取命令基础信息

如果用户想要搜索一个文件,而又想不起来应该使用哪个命令的时候。此时,apropos 命令就派上用可。

apropos 用来通过关键字查找定位手册页的名字和描述。它相当于使用带有 -k 选项的 man 命令。每个手册页里都有一个简短的描述。apropos 在这个描述中查找 keyword。keyword 是正则表达式,如果使用了选项 -r,或者包含通配符 (-w),或文本 (-e)。

例如:查询命令描述中包含 search 字符串的命令。如下:

[root@localhost ~]# apropos search
apropos (1)          - search the manual page names and descriptions
ausearch (8)         - a tool to query audit daemon logs
ausearch-expression (5) - audit search expression format
badblocks (8)        - search a device for bad blocks
find (1)             - search for files in a directory hierarchy
manpath (1)          - determine search path for manual pages
oldfind (1)          - search for files in a directory hierarchy
vgscan (8)           - Search for all volume groups
xzegrep (1)          - search compressed files for a regular expression
xzfgrep (1)          - search compressed files for a regular expression
xzgrep (1)           - search compressed files for a regular expression
zgrep (1)            - search possibly compressed files for a regular expression

注意:apropos 使用的数据库通过 mandb 命令来更新。

man 获取命令完整帮助手册

在 Linux 中获取帮助是一件非常容易的事情。Linux 为几乎每一个命令和系统调用编写了帮助手册。使用 man 命令可以方便地获取某个命令的帮助信息。

实例:使用 main 获取 find 命令的帮助信息。

[root@localhost ~]# man find
FIND(1)                                              General Commands Manual                                              FIND(1)

NAME
       find - search for files in a directory hierarchy

SYNOPSIS
       find [-H] [-L] [-P] [-D debugopts] [-Olevel] [path...] [expression]

DESCRIPTION
       This  manual  page documents the GNU version of find.  GNU find searches the directory tree rooted at each given file name
       by evaluating the given expression from left to right, according to the rules of precedence (see section OPERATORS), until
       the  outcome  is  known (the left hand side is false for and operations, true for or), at which point find moves on to the
       next file name.

       If you are using find in an environment where security is important (for example if you are using it to search directories
       that  are  writable by other users), you should read the "Security Considerations" chapter of the findutils documentation,
       which is called Finding Files and comes with findutils.   That document also includes a lot  more  detail  and  discussion
       than this manual page, so you may find it a more useful source of information.

OPTIONS
       The -H, -L and -P options control the treatment of symbolic links.  Command-line arguments following these are taken to be
       names of files or directories to be examined, up to the first argument that begins with `-', or the argument `('  or  `!'.
       That  argument  and  any  following arguments are taken to be the expression describing what is to be searched for.  If no
       paths are given, the current directory is used.  If no expression is given, the expression -print is used (but you  should
       probably consider using -print0 instead, anyway).

       This  manual  page  talks about `options' within the expression list.  These options control the behaviour of find but are
       specified immediately after the last path name.  The five `real' options -H, -L, -P, -D and  -O  must  appear  before  the
       first  path  name,  if  at  all.  A double dash -- can also be used to signal that any remaining arguments are not options
       (though ensuring that all start points begin with either `./' or `/' is generally safer if you use wildcards in  the  list
       of start points).

       -P     Never  follow symbolic links.  This is the default behaviour.  When find examines or prints information a file, and
              the file is a symbolic link, the information used shall be taken from the properties of the symbolic link itself.

       -L     Follow symbolic links.  When find examines or prints information about files, the information used shall  be  taken
 Manual page find(1) line 1 (press h for help or q to quit)

man 命令在显示手册页时实际调用的是 less 程序。可以通过方向键或J(表示向下)、K(表示向上)键上下翻动。空格键用于向下翻动一页。按下Q键则退出手册页面。

man 手册放置的在 /usr/share/man 目录,其中:

目   录内   容
/usr/share/man/man1普通命令和应用程序
/usr/share/man/man2系统调用
/usr/share/man/man3库调用,主要是 libc() 函数的使用文档
/usr/share/man/man4设备驱动和网络协议
/usr/share/man/man5文件的详细格式信息
/usr/share/man/man6游戏
/usr/share/man/man7文档使用说明
/usr/share/man/man8系统管理命令
/usr/share/man/man9内核源代码或模块的技术指标

其他方式

Linux 命令也可使用 --help 选项打印帮助信息(这里输出的帮助信息比较简洁,同时给出了所有的选项)。例如:

[root@localhost man]# ifconfig --help
Usage:
  ifconfig [-a] [-v] [-s] <interface> [[<AF>] <address>]
  [add <address>[/<prefixlen>]]
  [del <address>[/<prefixlen>]]
  [[-]broadcast [<address>]]  [[-]pointopoint [<address>]]
  [netmask <address>]  [dstaddr <address>]  [tunnel <address>]
  [outfill <NN>] [keepalive <NN>]
  [hw <HW> <address>]  [mtu <NN>]
  [[-]trailers]  [[-]arp]  [[-]allmulti]
  [multicast]  [[-]promisc]
  [mem_start <NN>]  [io_addr <NN>]  [irq <NN>]  [media <type>]
  [txqueuelen <NN>]
  [[-]dynamic]
  [up|down] ...

  <HW>=Hardware Type.
  List of possible hardware types:
    loop (Local Loopback) slip (Serial Line IP) cslip (VJ Serial Line IP)
    slip6 (6-bit Serial Line IP) cslip6 (VJ 6-bit Serial Line IP) adaptive (Adaptive Serial Line IP)
    ash (Ash) ether (Ethernet) ax25 (AMPR AX.25)
    netrom (AMPR NET/ROM) rose (AMPR ROSE) tunnel (IPIP Tunnel)
    ppp (Point-to-Point Protocol) hdlc ((Cisco)-HDLC) lapb (LAPB)
    arcnet (ARCnet) dlci (Frame Relay DLCI) frad (Frame Relay Access Device)
    sit (IPv6-in-IPv4) fddi (Fiber Distributed Data Interface) hippi (HIPPI)
    irda (IrLAP) ec (Econet) x25 (generic X.25)
    infiniband (InfiniBand) eui64 (Generic EUI-64)
  <AF>=Address family. Default: inet
  List of possible address families:
    unix (UNIX Domain) inet (DARPA Internet) inet6 (IPv6)
    ax25 (AMPR AX.25) netrom (AMPR NET/ROM) rose (AMPR ROSE)
    ipx (Novell IPX) ddp (Appletalk DDP) ec (Econet)
    ash (Ash) x25 (CCITT X.25)


说说我的看法
全部评论(
没有评论
关于
本网站属于个人的非赢利性网站,转载的文章遵循原作者的版权声明,如果原文没有版权声明,请来信告知:hxstrive@outlook.com
公众号