【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

你可能感兴趣的:(info,man,help)