Linux如何获取命令帮助

如何获取命令帮助

命令有两种类型:内置命令(shell内置),外部命令

builtinshell程序中实现的命令即为内建命令;

外部命令:在文件系统上某位置有一个与命令名称对应的可执行文件;

 

如何判断内部命令还是外部命令:使用type命令

[root@server~]# type ls
ls isaliased to `ls --color=auto'
[root@server~]# type mkdir
mkdir ishashed (/bin/mkdir)
[root@server~]# type cd
cd is a shellbuiltin
[root@server~]#

为何输入命令是不用绝对路径,直接输入命令即可?

shell:事先通过一个变量(PATH)设定好了多个路径,当用户输入命令时,shell会自动到这些路径下(由左向右)来查看与命令相同的可执行文件。

[root@server~]# echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

PATH变量是一组以冒号分隔的路径

查找的命令,执行的过的命令会被保存至一个hash查找表中;可以使用hash命令查看此表。

[root@server~]# hash
hits  command
   2       /usr/bin/file
   1       /bin/date
   3       /usr/bin/vim
   1       /bin/mount
   1       /bin/mv
   5       /usr/bin/yum
   2       /bin/mkdir
   9       /usr/bin/man
  13       /bin/ls
[root@server~]#

查看一个可执行程序的具体路径:使用"which"命令

[root@server~]# which file
/usr/bin/file

命令的格式:

       command options arguments

         命令    选项   参数

选项:修改命令执行的特性

       选项可以有多个,多个选项之间必须以空格分割

       短选项:--char(字符)

       长选项--word

       短选项可以合并,长选项一般不能合并

       有些选项需要参数;

命令参数:命令的作用对象

有些命令可以带多个参数;多个参数间需要使用空格分割;

       有些命令参数分隔机制不一样,如mount -o 参数分隔机制就是以逗号为分隔符

例:mount -t ext4 -o auto,exec,acl,rw /dev/sdb2/mnt/sdb

 

修改命令的执行特性

例:ls命令默认不显示颜色,加入--color=auto再显示时,就显示出了颜色

因系统设置ls别名为:ls --color=auto

所以命令自身就显示颜色,要想使用命令本身而不是命令别名\ls即可                         

wKioL1hgjmngyBhOAABM8MU2Bak934.png-wh_50

wKiom1hgjmqioz5sAABEm9OFVoA550.png-wh_50

 


获取帮助:

       内置命令:

              #helpcommand

              例:helpcd

[root@server~]# help cd
cd: cd[-L|-P] [dir]
    Change the shell working directory.
    
    Change the current directory to DIR.  The default DIR is the value of the
    HOME shell variable.
    
    The variable CDPATH defines the search pathfor the directory containing
    DIR. Alternative directory names in CDPATH are separated by a colon (:).
    A null directory name is the same as thecurrent directory.  If DIR begins
    with a slash (/), then CDPATH is not used.
    
    If the directory is not found, and theshell option `cdable_vars' is set,
    the word is assumed to be  a variable name.  If that variable has a value,
    its value is used for DIR.
    
    Options:
        -L    forcesymbolic links to be followed
        -P    usethe physical directory structure without following symbolic
           links
    
    The default is to follow symbolic links, asif `-L' were specified.
    
    Exit Status:
    Returns 0 if the directory is changed;non-zero otherwise.
    [root@server ~]#

       外部命令:

              #命令--help

              例:file--help

 [root@server ~]# file --help
Usage:file [OPTION...] [FILE...]
Determinetype of FILEs.
 
      --help                 display this help and exit
  -v, --version              output version information andexit
  -m, --magic-file LIST      use LIST as a colon-separated list ofmagic
                               number files
  -z, --uncompress           try to look inside compressed files
  -b, --brief                do not prepend filenames tooutput lines
  -c, --checking-printout    print the parsed form of the magic file,use in
                               conjunction with-m to debug a new magic file
                               beforeinstalling it
  -e, --exclude TEST         exclude TEST from the list of test tobe
                               performed forfile. Valid tests are:
                               ascii, apptype,compress, elf, soft, tar, tokens, troff
  -f, --files-from FILE      read the filenames to be examined fromFILE
  -F, --separator STRING     use string as separator instead of `:'
  -i, --mime                 output MIME type strings(--mime-type and
                               --mime-encoding)
      --apple                output the Apple CREATOR/TYPE
      --mime-type            output the MIME type
      --mime-encoding        output the MIME encoding
  -k, --keep-going           don't stop at the first match
  -L, --dereference          follow symlinks (default)
  -h, --no-dereference       don't follow symlinks
  -n, --no-buffer            do not buffer output
  -N, --no-pad               do not pad output
  -0, --print0               terminate filenames with ASCIINUL
  -p, --preserve-date        preserve access times on files
  -r, --raw                  don't translate unprintablechars to \ooo
  -s, --special-files        treat special (block/char devices)files as
                             ordinary ones
  -C, --compile              compile file specified by -m
  -d,--debug                print debuggingmessages

使用手册:manual

#man 命令  先解压在显示  调用tar命令

       常用段落说明:

              NAME 简要帮助说明

              SYNOPSIS 使用格式

              DESCRIPTION 详细功能描述

              OPPTIONS 选项

              EXAMPLES 使用实例

       使用帮助中命令格式中的字符意义:

              <>:必选的部分

              []:可选的部分

              ...:同类内容可以出现多个,空格分隔

              a|b:或者,只能选其一,a或者b

man的简要使用机制: less

       翻屏:

              空格键:向文件尾部翻一屏;

              b:向文件首部翻一屏;

              回车键:向文件尾部翻一行;

              k:向文件首部翻一行;

              Ctrl+d:向文件尾部翻半屏;

              Ctrl+u:向文件首部翻半屏;

      

       文本搜索:区分大小写

              /keyword:向文件尾部搜索;

              ?keyword:向文件首部搜索;

                     n:跟搜索命令相同的方向(下一个)

                     N:跟搜索命令相反的方向(上一个)

       快速跳转

              快速跳转到文件首部1G

              快速跳转到文件尾部G

       退出

       q:退出;

 

man的章节机制:共8

       1UserCommands(用户命令)

       2SystemCalls(系统调用)

       3CLibrary Functions(库调用)

       4Devicesand Special Files(设备文件)

       5FileFormats and Conventions(配置文件格式说明)

       6Gameset. Al.(游戏)

       7Miscellanea(杂项)

       8SystemAdministration tools and Deamons(管理员命令)

精确查找某些关键字在哪些段落中有使用帮助,可以使用:whatis命令

       #whatis Keyword

       #whaitis ls

[root@server ~]# whatis mkdir
 mkdir                (1)  - make directories
mkdir                (1p)  - make directories
mkdir                (2)  - create a directory
 mkdir                (3p)  - make a directory

mkdir命令在第123章节都有

如果想查看指定章节内容

man 章节命令

提示:新装的系统一般whatis数据尚未生成,一般等一会即可生成,或者使用makewhatis手动进行生成

模糊查找某些关键字在哪些段落中有使用帮助,可以使用man -k 选项

       #man -k keyword

       #man -k mkdir

 [root@server ~]# man -k mkdir
mkdir                (1)  - make directories
mkdir                (1p)  - make directories
 mkdir                (2)  - create a directory
mkdir                (3p)  - make a directory
mkdirat              (2)  - create a directory relative to a directoryfile descriptor

其他帮助获取方式:

获取在线文档:info

程序的自带文档:/usr/share/doc/

google

查找指定格式的文件

              keyword filetype:ppt

              linux filetype:ppt

在指定的网站中查找

              keyword site:网页

RedHat官方文档

https://access.redhat.com/documentation/en/


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章