zoukankan      html  css  js  c++  java
  • Linux命令之man

    在Linux命令中,我们不可能所有的命令都要去记。如果遇到没有见过的命令该怎么办呢?就得查看命令帮助文档,这样不仅仅提升了自学能力,而且让自己印象更加深刻。在linux中,常用查看命令帮助的方法:

    1. type 命令,可以显示一个命令的类型。type echo 会显示echo is a shell builtin,你起码可以知道这是一个shell内嵌的命令。type ping,会显示 ping is /bin/ping,你会知道ping是引用的/bin/ping这个应用程序。
    2. which 命令,可以显示一个命令所处的位置。which ls,会显示 /bin/ls。which echo,会显示/bin/echo。

    3. whatis 命令,可以显示一个命令的简短描述。whatis ls ,会显示 ls (1) - list directory contents。

    4. 命令 –help ,一般可以显示这个命令的帮助信息。

    5. man 命令,可以显示命令的Manual。在man命令下底行模式:
      / 查找关键字
      n/N 下一个/上一个
      q 离开
      man -k 列出包含keyword关键字的手册页

    6. info 命令,查看命令详细的说明文件
      注:info查看的是比man更详细的说明,也就是把man的页再划分为更小的章节
      同时这个命令还可以链接到相似主题
      info命令底行模式:
      arrows.pageUp.pageDown 切换
      Tab 跳往下一个链接(有*的地方)
      Enter 进入链接
      n/p/u 跳往下一个(上一个)小节,上一层章节
      s[] 查找关键字
      q 离开

    这节主要讲解man的使用,man是manual(操作说明)的简写,只要执行“man 命令”就会得到命令的详细说明。下面以命令ls为例:

    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
           specified.
    
           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
            ...中间省略
            ...中间省略
    
           --help display this help and exit
    
           --version
                  output version information and exit
    
           The  SIZE argument is an integer and optional unit (example: 10K is 10*1024).  Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,...
           (powers of 1000).
    
           Using color to distinguish file types is disabled both by default and with --color=never.  With --color=auto,  ls  emits  color  codes
           only  when standard output is connected to a terminal.  The LS_COLORS environment variable can change the settings.  Use the dircolors
           command to set it.
    
       Exit status:
           0      if OK,
    
           1      if minor problems (e.g., cannot access subdirectory),
    
           2      if serious trouble (e.g., cannot access command-line argument).
    
    AUTHOR
           Written by Richard M. Stallman and David MacKenzie.
    
    REPORTING BUGS
           GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
           Report ls translation bugs to <http://translationproject.org/team/>
    
    COPYRIGHT
           Copyright © 2016 Free Software Foundation, Inc.  License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
           This is free software: you are free to change and redistribute it.  There is NO WARRANTY, to the extent permitted by law.
    
    SEE ALSO
           Full documentation at: <http://www.gnu.org/software/coreutils/ls>
           or available locally via: info '(coreutils) ls invocation'
    
    GNU coreutils 8.25                                              February 2016                                                           LS(1)

    从左上角可看到LS(1) ,这里的“1”代表用户在shell环境中可以操作的命令或可执行文件。

    代号 代表内容(英文) 代表内容(中文)
    1 Executable programs or shell commands 用户在shell环境中可以操作的命令或可执行文件
    2 System calls (functions provided by the kernel) 系统内核可调用的函数与工具等
    3 Library calls (functions within program libraries) 一些常用的函数(function)与函数库(library),大部分为C的函数库(libc)
    4 Special files (usually found in /dev) 设备文件的说明,通常在/dev下的文件
    5 File formats and conventions eg /etc/passwd 配置文件或者是某些文件的格式
    6 Games 游戏(games)
    7 Miscellaneous (including macro packages and conventions), e.g. man(7), groff(7) 惯例与协议等,例如linux文件系统,网络协议,ASCII code等说明
    8 System administration commands (usually only for root) 系统管理员可用的管理命令
    9 Kernel routines [Non standard] 跟kernel有关的文件
    • man page主要分为下面几个部分:
    代号 内容说明 
    NAME 简短的说明、数据名称说明
    SYNOPSIS 简短的命令执行语法(syntax)简介
    DESCRIPTION 较为完整的说明,这部分最好仔细看
    OPTIONS  针对SYNOPSIS部分中,有列举的所有可用的选项说明
    COMMANDS 当这个程序(软件)在执行的时候,可以在此程序中执行的命令
    FILES 这个程序或数据所使用或参考或连接到的某些文件
    SEE ALSO 这个命令或数据有相关的其他说明
    EXAMPLE 一些课参考的范例
    BUGS 是否有相关的错误

    SYNOPSIS下的命令语法格式说明:

    []
    表示是可选的
    <>
    表示是可变化的
    x|y|z
    表示只能在x、y、z中选择一个
    -abc
    表示三个参数(或任何二个)的混合使用
    ...
    同一内容可出现多次
    {}
       分组
    _____
    在参数选项下有下划线,目前还不知道作用

     man的快捷键:

    按键 进行工作
    空格键 向下翻一页
    [Page Down] 向下翻一页
    [Page Up] 向上翻一页
    [Home] 去到第一页
    [End] 去到最好一页
    /string 向下查询string字符串,如果要查询ABC,就输入/ABC
    ?string 向上查询string字符串,如果要查询ABC,就输入?ABC
    n,N

    利用/或?查询字符串时,可以用n来继续下一个查询(不论是/或?)。可以利用N进行反向查询。举例来说,以/ABC来查询ABC字符串

    可以n继续向下查询,N向上查询。以?ABC来查询ABC字符串,则用n来向上查询,N向下查询。

    q

    结束这次的man page

    备注:命令分为shell内置命令和非shell内置命令。非shell内置命令可以用man、info、cmd --help查看帮助文档,但是shell内置命令不可以这样查询,只能用help cmd查看。那我们怎么知道是否是shell命令呢?我们可以通过type cmd查询。
    vbird@Ubuntu1604:~$ type -a cd
    cd is a shell builtin
    vbird@Ubuntu1604:~$ type -a pwd   //pwd既是shell命令,也是非shell命令.
    pwd is a shell builtin
    pwd is /bin/pwd
    vbird@Ubuntu1604:~$ man cd       //用man查询shell内置命令查不到帮助文档.
    No manual entry for cd
    vbird@Ubuntu1604:~$ help cd       //可以用help cmd查询shell内置命令帮助文档.
    cd: cd [-L|[-P [-e]] [-@]] [dir]
        Change the shell working directory.
    省略...
    vbird@Ubuntu1604:~$ man pwd        //可以用man查询命令,但这帮助文档是适用于/bin/pwd.
    vbird@Ubuntu1604:~$ help pwd       //可以用help cmd查询命令,此帮助文档是适用于shell内置的pwd命令.
    pwd: pwd [-LP]
        Print the name of the current working directory.
    省略...
  • 相关阅读:
    axios express设置跨域允许传递cookie
    yarn常用命令指北
    Web代理工具NProxy
    DevOps的了解
    css图片hover放大
    autoprefixer
    谈谈浏览器http缓存
    欢迎使用 MWeb
    优化关键渲染路径CRP
    chrome 61 更新
  • 原文地址:https://www.cnblogs.com/hwli/p/9608793.html
Copyright © 2011-2022 走看看