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/


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