【Linux命令詳解】9、在Linux下獲取幫助—(help、man、info)

9、在linux系統下獲取幫助

本節主要學習在linux系統下如何獲取和使用幫助,這些命令有help、man、info等。

9.1 help:

可以查看內部Shell命令的幫助信息。

9.1.1 命令語法:

     help[選項][命令]

9.1.2選項參數:

help命令選項含義:

-d   顯示命令簡短的主題描述

-s   顯示命令簡短的語法描述

9.1.3 實例:

例1:查看能使用help命令查看幫助信息的命令。

[root@ser01 ~]# help    
GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)      
These shell commands are defined internally.  Type `help' to see this list.      
Type `help name' to find out more about the function `name'.      
Use `info bash' to find out more about the shell in general.      
Use `man -k' or `info' to find out more about commands not in this list.

A star (*) next to a name means that the command is disabled.

job_spec [&]                             history [-c] [-d offset] [n] or histo>    
(( expression ))                         if COMMANDS; then COMMANDS; [ elif CO>      
. filename [arguments]                   jobs [-lnprs] [jobspec ...] or jobs ->      
:                                        kill [-s sigspec | -n signum | -sigsp>      
[ arg... ]                               let arg [arg ...]      
` expression `                         local [option] name[=value] ...      
alias [-p] [name[=value] ... ]           logout [n]      
bg [job_spec ...]                        mapfile [-n count] [-O origin] [-s co>      
bind [-lpvsPVS] [-m keymap] [-f filena>  popd [-n] [+N | -N]      
break [n]                                printf [-v var] format [arguments]      
builtin [shell-builtin [arg ...]]        pushd [-n] [+N | -N | dir]      
caller [expr]                            pwd [-LP]      
case WORD in [PATTERN [| PATTERN]...) >  read [-ers] [-a array] [-d delim] [-i>      
cd [-L|-P] [dir]                         readarray [-n count] [-O origin] [-s >      
command [-pVv] command [arg ...]         readonly [-af] [name[=value] ...] or >      
compgen [-abcdefgjksuv] [-o option]  [>  return [n]      
complete [-abcdefgjksuv] [-pr] [-DE] [>  select NAME [in WORDS ... ;] do COMMA>      
compopt [-o|+o option] [-DE] [name ...>  set [--abefhkmnptuvxBCHP] [-o option->      
continue [n]                             shift [n]      
coproc [NAME] command [redirections]     shopt [-pqsu] [-o] [optname ...]      
declare [-aAfFilrtux] [-p] [name[=valu>  source filename [arguments]      
dirs [-clpv] [+N] [-N]                   suspend [-f]      
disown [-h] [-ar] [jobspec ...]          test [expr]      
echo [-neE] [arg ...]                    time [-p] pipeline      
enable [-a] [-dnps] [-f filename] [nam>  times      
eval [arg ...]                           trap [-lp] [[arg] signal_spec ...]      
exec [-cl] [-a name] [command [argumen>  true      
exit [n]                                 type [-afptP] name [name ...]      
export [-fn] [name[=value] ...] or exp>  typeset [-aAfFilrtux] [-p] name[=valu>      
false                                    ulimit [-SHacdefilmnpqrstuvx] [limit]>      
fc [-e ename] [-lnr] [first] [last] or>  umask [-p] [-S] [mode]      
fg [job_spec]                            unalias [-a] name [name ...]      
for NAME [in WORDS ... ] ; do COMMANDS>  unset [-f] [-v] [name ...]      
for (( exp1; exp2; exp3 )); do COMMAND>  until COMMANDS; do COMMANDS; done      
function name { COMMANDS ; } or name (>  variables - Names and meanings of som>      
getopts optstring name [arg]             wait [id]      
hash [-lr] [-p pathname] [-dt] [name .>  while COMMANDS; do COMMANDS; done      
help [-dms] [pattern ...]                { COMMANDS ; }

例2:使用help命令查看pwd命令詳細的幫助信息。

[root@ser01 ~]# help pwd    
pwd: pwd [-LP]      
    Print the name of the current working directory.      
   
    Options:      
      -L        print the value of $PWD if it names the current working      
        directory      
      -P        print the physical directory, without any symbolic links      
   
    By default, `pwd' behaves as if `-L' were specified.      
   
    Exit Status:      
    Returns 0 unless an invalid option is given or the current directory      
    cannot be read.

例3:使用help命令查看pwd命令簡短的語法描述。

[root@ser01 ~]# help -s pwd    
pwd: pwd [-LP]

例4:使用help命令查看pwd命令簡短的主題描述。

[root@ser01 ~]# help -d pwd    
pwd - Print the name of the current working directory.

9.2 man:

可以用來查看命令、函數或者是文件的幫助手冊,另外它還可以顯示一些gzip壓縮格式的文件。

一般情況下man手冊頁的資源主要位於/usr/share/man目錄下。

注:

     man手冊頁類型

類型:                          描述:

1                                   用戶命令

2                                   系統調用

3                                   C語言函數庫

4                                   設備和特殊文件

5                                   文件格式和約定

6                                   遊戲程序

7                                   雜記

8                                   系統管理工具

9                                   Linux內核API(內核調用)

     man手冊頁組成內容

手冊頁內容:                                                  描述:

Header                                                           標題

NAME                                                             命令/函數的功能概述

SYNOPSIS                                                      命令/函數用法的簡單描述

AVAILABILITY                                                可用性說明

DESCRIPTION                                                命令/函數的詳細描述

OPTIONS                                                        該命令的所有可選項的詳細說明

RETURN  VALUE                                            如果是函數,則列出函數返回值

ERRORS                                                          如果函數調用出錯,則列出所有出錯的值和可能引起錯誤的原因

FILES                                                               該命令/函數所用到的相關係統文件

ENVIRONMENT                                             和該命令/函數相關的環境變量

NOTES                                                            表示不常用的用法或實現的細節

BUGS                                                               已知的錯誤和警告

HISTORY                                                         該命令/函數的歷史發展

SEE ALSO                                                        可以參照的其他的相關命令/函數

Others                                                             和一些具體命名/函數有關的特殊信息

EXAMPLES                                                      命令/函數的示例

9.2.1 命令語法:

man[選項][名稱]

9.2.2  選項參數:

選項:                          選項含義:

-M<路徑>                   指定man手冊頁的搜索路徑

-a                                  顯示所有的手冊頁,而不是隻顯示第一個

-d                                 主要用於檢查,如果用戶加入了一個新的文件,就可以用這個選項檢查是否出錯,這個選項並不會列出文件內容

-f                                  只顯示出命令的功能而不顯示詳細的說明文件,和whatis命令功能一樣

-p                                 字符串設定運行的預先處理程序的順序

-w                                 不顯示手冊頁內容,只顯示將被格式化和顯示的文件所在位置

9.2.3 實例:

例1:顯示pwd命令的man手冊頁。

[root@docekr ~]# man pwd    
PWD(1)                            User Commands                           PWD(1)

NAME     //名稱    
       pwd - print name of current/working directory

SYNOPSIS   //內容簡介      
       pwd [OPTION]...

DESCRIPTION  //描述      
       Print the full filename of the current working directory.

       -L, --logical    
              use PWD from environment, even if it contains symlinks

       -P, --physical    
              avoid all symlinks

       --help display this help and exit

       --version    
              output version information and exit

       NOTE:  your  shell  may have its own version of pwd, which usually super‐    
       sedes the version described here.  Please refer to your shell's  documen‐      
       tation for details about the options it supports.

       GNU   coreutils   online  help:  <http://www.gnu.org/software/coreutils/>    
       Report pwd translation bugs to <
http://translationproject.org/team/>

AUTHOR   //作者      
       Written by Jim Meyering.

COPYRIGHT  //版權聲明      
       Copyright ? 2013 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  //可參考內容      
       getcwd(3)

       The full documentation for pwd is maintained as a Texinfo manual.  If the    
       info and pwd programs are properly installed at your site, the command

              info coreutils 'pwd invocation'

       should give you access to the complete manual.

GNU coreutils 8.22                  June 2014                             PWD(1)    
Manual page pwd(1) line 26/53 (END) (press h for help or q to quit)      
       sedes the version described here.  Please refer to your shell's  documen‐      
       tation for details about the options it supports.

       GNU   coreutils   online  help:  <http://www.gnu.org/software/coreutils/>    
       Report pwd translation bugs to <
http://translationproject.org/team/>

AUTHOR    
       Written by Jim Meyering.

COPYRIGHT    
       Copyright ? 2013 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    
       getcwd(3)

       The full documentation for pwd is maintained as a Texinfo manual.  If the    
       info and pwd programs are properly installed at your site, the command

              info coreutils 'pwd invocation'

       should give you access to the complete manual.

GNU coreutils 8.22                  June 2014                             PWD(1)    
~

例2:查看/etc/passwd文件的man手冊頁

[root@docekr ~]# man 1 passwd  
PASSWD(1)                                                                                                   User utilities                                                                                                   PASSWD(1)

NAME  
       passwd - update user's authentication tokens

SYNOPSIS  
       passwd [-k] [-l] [-u [-f]] [-d] [-e] [-n mindays] [-x maxdays] [-w warndays] [-i inactivedays] [-S] [--stdin] [username]

DESCRIPTION  
       The passwd utility is used to update user's authentication token(s).

       This  task  is  achieved  through  calls  to the Linux-PAM and Libuser API.  Essentially, it initializes itself as a "passwd" service with Linux-PAM and utilizes configured password modules to authenticate and then update a  
       user's password.

       A simple entry in the global Linux-PAM configuration file for this service would be:

        #  
        # passwd service entry that does strength checking of    
        # a proposed password before updating it.    
        #    
        passwd password requisite pam_cracklib.so retry=3    
        passwd password required pam_unix.so use_authtok    
        #

       Note, other module types are not required for this application to function correctly.

OPTIONS  
       -k, --keep    
              The option -k is used to indicate that the update should only be for expired authentication tokens (passwords); the user wishes to keep their non-expired tokens as before.

       -l, --lock  
              This option is used to lock the password of specified account and it is available to root only. The locking is performed by rendering the encrypted password into an invalid string (by prefixing the  encrypted  string    
              with an !). Note that the account is not fully locked - the user can still log in by other means of authentication such as the ssh public key authentication. Use chage -E 0 user command instead for full account lock‐    
              ing.

       --stdin  
              This option is used to indicate that passwd should read the new password from standard input, which can be a pipe.

       -u, --unlock  
              This is the reverse of the -l option - it will unlock the account password by removing the ! prefix. This option is available to root only. By default passwd will refuse to create a passwordless account (it will  not    
              unlock an account that has only "!" as a password). The force option -f will override this protection.

       -d, --delete  
              This is a quick way to delete a password for an account. It will set the named account passwordless. Available to root only.

       -e, --expire  
              This is a quick way to expire a password for an account. The user will be forced to change the password during the next login attempt.  Available to root only.

       -f, --force  
              Force the specified operation.

       -n, --minimum DAYS  
              This will set the minimum password lifetime, in days, if the user's account supports password lifetimes.  Available to root only.

       -x, --maximum DAYS  
              This will set the maximum password lifetime, in days, if the user's account supports password lifetimes.  Available to root only.

       -w, --warning DAYS  
              This will set the number of days in advance the user will begin receiving warnings that her password will expire, if the user's account supports password lifetimes.  Available to root only.

       -i, --inactive DAYS  
              This  will  set  the number of days which will pass before an expired password for this account will be taken to mean that the account is inactive and should be disabled, if the user's account supports password life‐    
              times.  Available to root only.

       -S, --status  
              This will output a short information about the status of the password for a given account. Available to root user only.

Remember the following two principles  
       Protect your password.    
              Don't write down your password - memorize it.  In particular, don't write it down and leave it anywhere, and don't place it in an unencrypted file!  Use unrelated passwords for systems controlled by different organi‐    
              zations.   Don't  give  or share your password, in particular to someone claiming to be from computer support or a vendor.  Don't let anyone watch you enter your password.  Don't enter your password to a computer you    
              don't trust or if things "look funny"; someone may be trying to hijack your password.  Use the password for a limited time and change it periodically.

       Choose a hard-to-guess password.  
              passwd through the calls to the pam_cracklib PAM module will try to prevent you from choosing a really bad password, but it isn't foolproof; create your password wisely.  Don't use something you'd find in  a  dictio‐    
              nary  (in  any  language  or  jargon).   Don't use a name (including that of a spouse, parent, child, pet, fantasy character, famous person, and location) or any variation of your personal or account name.  Don't use    
              accessible information about you (such as your phone number, license plate, or social security number) or your environment.  Don't use a birthday or a simple pattern (such as "qwerty", "abc", or  "aaa").   Don't  use    
              any  of  those backwards, followed by a digit, or preceded by a digit. Instead, use a mixture of upper and lower case letters, as well as digits or punctuation.  When choosing a new password, make sure it's unrelated    
              to any previous password. Use long passwords (say at least 8 characters long).  You might use a word pair with punctuation inserted, a passphrase (an understandable sequence of words), or the  first  letter  of  each    
              word in a passphrase.

       These principles are partially enforced by the system, but only partly so.  Vigilance on your part will make the system much more secure.

EXIT CODE  
       On successful completion of its task, passwd will complete with exit code 0.  An exit code of 1 indicates an error occurred.  Textual errors are written to the standard error stream.

CONFORMING TO  
       Linux-PAM (Pluggable Authentication modules for Linux).

FILES  
       /etc/pam.d/passwd - the Linux-PAM configuration file

BUGS  
       None known.

SEE ALSO  
       pam(8), pam.d(5), libuser.conf(5), and pam_chauthtok(3).

       For more complete information on how to configure this application with Linux-PAM, see the Linux-PAM System Administrators' Guide.

AUTHOR  
       Cristian Gafton <[email protected]>

GNU/Linux                                                                                                     Jun 20 2012                                                                                                    PASSWD(1)  

例3:顯示passwd命令和/etc/passwd文件手冊頁所在位置。

[root@docekr ~]# man -w passwd  
/usr/share/man/man1/passwd.1.gz

 

9.3 info

它可以用來查看幫助信息,支持鏈接跳轉功能,info文檔都存放在/usr/share/info目錄中。

9.3.1命令語法:

info[選項][菜單項目]

9.3.2 選項參數:

                             info命令選項參數

選項                                         選項含義

-w                                            顯示info文檔的物理位置

-f<info文件>                          指定要訪問的info文件

-o<文件>                                將選中的節點全輸出到指定文件

-w                                            顯示info文件在系統中的位置

-n<節點>                                在首個瀏覽過的info文件中指定節點

-O                                            跳轉至命令行選項節點

9.3.3 實例:

例1:查看linux系統中info文檔的分類列表

[root@docekr ~]# info

Libraries  
* History: (history).           The GNU history library API.    
* RLuserman: (rluserman).       The GNU readline library User's Manual.

Localization  
* idn: (libidn)Invoking idn.    Internationalized Domain Name (IDN) string    
                                  conversion.

Software development  
* As: (as).                     The GNU assembler.    
* Binutils: (binutils).         The GNU binary utilities.    
* Gas: (as).                    The GNU assembler.    
* Ld: (ld).                     The GNU linker.    
* Make: (make).                 The GNU make utility.    
* gprof: (gprof).               Profiling your program's execution

Software libraries  
* libidn: (libidn).             Internationalized string processing library.

System administration  
* Which: (which).               Show full path of commands.    
* parted: (parted).             GNU partitioning software

Texinfo documentation system  
* Info: (info).                 Documentation browsing system.

Miscellaneous  
* bash: (bash).                 The Bourne Again Shell.

Text creation and manipulation  
* Diffutils: (diffutils).       Comparing and merging files.    
* Gawk: (gawk).                 A text scanning and processing language.    
* grep: (grep).                 Print lines matching a pattern.    
* sed: (sed).                   Stream EDitor. 


-----Info: (dir)Top, 295 lines --Bot------------------------------------------------

例2:查看ls命令的info文檔

[root@docekr ~]# info ls  
File: coreutils.info,  Node: cp invocation,  Next: dd invocation,  Up: Basic operations

11.1 'cp': Copy files and directories  
=====================================

'cp' copies files (or, optionally, directories).  The copy is completely  
independent of the original.  You can either copy one file to another,    
or copy arbitrarily many files to a destination directory.  Synopses:

     cp [OPTION]... [-T] SOURCE DEST  
     cp [OPTION]... SOURCE... DIRECTORY    
     cp [OPTION]... -t DIRECTORY SOURCE...

   * If two file names are given, 'cp' copies the first file to the  
     second.

   * If the '--target-directory' ('-t') option is given, or failing that  
     if the last file is a directory and the '--no-target-directory'    
     ('-T') option is not given, 'cp' copies each SOURCE file to the    
     specified directory, using the SOURCEs' names.

   Generally, files are written just as they are read.  For exceptions,  
see the '--sparse' option below.

   By default, 'cp' does not copy directories.  However, the '-R', '-a',  
and '-r' options cause 'cp' to copy recursively by descending into    
source directories and copying files to corresponding destination    
directories.

   When copying from a symbolic link, 'cp' normally follows the link  
only when not copying recursively or when '--link' ('-l') is used.  This    
default can be overridden with the '--archive' ('-a'), '-d',    
'--dereference' ('-L'), '--no-dereference' ('-P'), and '-H' options.  If    
more than one of these options is specified, the last one silently    
overrides the others.

   When copying to a symbolic link, 'cp' follows the link only when it  
refers to an existing regular file.  However, when copying to a dangling    
symbolic link, 'cp' refuses by default, and fails with a diagnostic,    
since the operation is inherently dangerous.  This behavior is contrary    
to historical practice and to POSIX.  Set 'POSIXLY_CORRECT' to make 'cp'    
attempt to create the target of a dangling destination symlink, in spite    
of the possible risk.  Also, when an option like '--backup' or '--link'    
acts to rename or remove the destination before copying, 'cp' renames or    
removes the symbolic link rather than the file it points to.

   By default, 'cp' copies the contents of special files only when not  
copying recursively.  This default can be overridden with the    
'--copy-contents' option.

   'cp' generally refuses to copy a file onto itself, with the following  
exception: if '--force --backup' is specified with SOURCE and DEST    
identical, and referring to a regular file, 'cp' will make a backup    
file, either regular or numbered, as specified in the usual ways (*note    
Backup options::).  This is useful when you simply want to make a backup    
of an existing file before changing it.

   The program accepts the following options.  Also see *note Common  
options::.

'-a'  
'--archive'    
     Preserve as much as possible of the structure and attributes of the    
     original files in the copy (but do not attempt to preserve internal    
     directory structure; i.e., 'ls -U' may list the entries in a copied    
     directory in a different order).  Try to preserve SELinux security    
     context and extended attributes (xattr), but ignore any failure to    
--zz-Info: (coreutils.info.gz)cp invocation, 392 lines --Top-----------

例3:顯示ls命令info文檔的物理位置

[root@docekr ~]# info -w ls  
/usr/share/info/coreutils.info.gz

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