美文网首页
Ubuntu终端中帮助信息的获取

Ubuntu终端中帮助信息的获取

作者: vvaa01 | 来源:发表于2018-10-12 09:00 被阅读0次

    Linux操作系统中命令繁多,再加上每个命令都有许多的选项或参数,记忆困难,使得大多数人在刚接触命令行时无法适应。其实,Linux操作系统命令行工具中本身就包含有一些帮助文件,而且也有在线帮助文档可以参考。

    help命令

    help命令在这里的作用时查看内建命令的作用及使用方法,比如内建命令中最常用的“cd”(change directory)命令,具体如下:

    【示例】使用help命令查看cd命令的使用方法
    #输入help指令
    os@tedu:~$ help cd
    #输出相应的帮助信息
    cd: cd [-L|[-P [-e]] [-@]] [目录]
        改变 shell 工作目录。
        改变当前目录至 DIR 目录。默认的 DIR 目录是 shell 变量 HOME的值。
        变量 CDPATH 定义了含有 DIR 的目录的搜索路径,其中不同的目录名称由冒号 (:)分隔。
        一个空的目录名称表示当前目录。如果要切换到的 DIR 由斜杠 (/) 开头,则 CDPATH
        变量不会被使用。
        如果路径找不到,并且 shell 选项 ‘cdable_vars' 被设定,则参数词被假定为一个
        变量名。如果该变量有值,则它的值被当作 DIR 目录。
        选项:
            -L  强制跟随符号链接: 在处理 ‘..' 之后解析 DIR 中的符号链接。
            -P  使用物理目录结构而不跟随符号链接: 在处理 ‘..' 之前解析 DIR 中的符号链接。
            -e  如果使用了 -P 参数,但不能成功确定当前工作目录时,返回非零的返回值。
            -@  在支持拓展属性的系统上,将一个有这些属性的文件当作有文件属性的目录。
        默认情况下跟随符号链接,如同指定 ‘-L'。
    

    帮助选项

    对于外部命令来说,一般其都会有自带的帮助文档,可以在使用“命令 --help”的指令将文档输出到终端中,具体如下:

    #使用—help帮助选项查看命令的使用方法
    #ls并非内建命令,所以help命令无法输出其帮助文档
    os@tedu:~$ help ls
    bash: help: 没有与 ‘ls' 匹配的帮助主题。尝试 ‘help help' 或 ‘man -k ls' 或 ‘info ls'。
    #可以使用“--help”选项输出帮助文档
    os@tedu:~$ ls --help
    用法:ls [选项]... [文件]...
    List information about the FILEs (the current directory by default).
    Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.
    
    必选参数对长短选项同时适用。
      -a, --all         不隐藏任何以. 开始的项目
      -A, --almost-all      列出除. 及.. 以外的任何项目
          --author          与-l 同时使用时列出每个文件的作者
      -b, --escape          以八进制溢出序列表示不可打印的字符
          --block-size=SIZE      scale sizes by SIZE before printing them; e.g.,
                                   '--block-size=M' prints sizes in units of
                                   1,048,576 bytes; see SIZE format below
      -B, --ignore-backups       do not list implied entries ending with ~
      -c                         with -lt: sort by, and show, ctime (time of last
                                   modification of file status information);
                                   with -l: show ctime and sort by name;
                                   otherwise: sort by ctime, newest first
      -C                         list entries by columns
          --color[=WHEN]         colorize the output; WHEN can be 'always' (default
                                   if omitted), 'auto', or 'never'; more info below
      -d, --directory            list directories themselves, not their contents
      -D, --dired                generate output designed for Emacs' dired mode
    ......省略
    

    “手册页”是Unix或其他类Unix系统中普遍存在的一种在线文档,内容包括计算机程序(库和应用程序)、标准或惯例、甚至抽象概念,可以通过man(manual,操作手册)命令来进行查阅,常用格式为:

    man 命令
    

    例如,依然以“ls”为例,除了“--help”选项外,可以使用“man”命令查看其在线帮助文档:

    使用man命令查看ls命令的帮助信息
    #输入man ls进行帮助信息查询
    os@tedu:~$ man ls
    #注意:命令执行后,会进入man命令的环境,显示以下内容
    LS(1)                            User Commands                           LS(1)
    NAME    #命令名称
           ls - list directory contents
    SYNOPSIS    #命令概要
           ls [OPTION]... [FILE]...
    DESCRIPTION     #命令各选项详细说明
           List  information  about  the FILEs (the current directory by default).
           Sort entries alphabetically if none of -cftuvSUX nor --sort  is  speci‐
           fied.
           Mandatory  arguments  to  long  options are mandatory for short options
           too.
           -a, --all
                  do not ignore entries starting with .
           -A, --almost-all
                  do not list implied . and ..
           --author
                  with -l, print the author of each file
           -b, --escape
                  print C-style escapes for nongraphic characters
           --block-size=SIZE
                  scale sizes by SIZE before printing them; e.g., '--block-size=M'
                  prints sizes in units of 1,048,576 bytes; see SIZE format below
           -B, --ignore-backups
                  do not list implied entries ending with ~
           -c     with -lt: sort by, and show, ctime (time of last modification of
                  file status information); with -l: show ctime and sort by  name;
                  otherwise: sort by ctime, newest first
           -C     list entries by columns
    #帮助文档较长,可以由鼠标滚轮来进行滚屏,或是空格来切换下一页
    #在man当前状态直接输入“h”打开man命令帮助文档,“q”退出man命令
    Manual page ls(1) line 1 (press h for help or q to quit)
    

    一般来说,man page的内容大致分为以下几个部分。


    man命令中常见的几个部分

    相关文章

      网友评论

          本文标题:Ubuntu终端中帮助信息的获取

          本文链接:https://www.haomeiwen.com/subject/herwaftx.html