原创Blog,转载请注明出处

http://blog.csdn.net/hello_hwc

我的虚拟机系统是CentOS,版本较老,谅解

一、为什么要学习帮助命令?
  授人以鱼不如授人以渔,学会了怎么看帮助文档,是寻找到一个解决一类问题,而不是一个问题的方法。


二、常用的几个命名
1、man

-w  打印相关帮助文档的位置
-k 在man页中查找指定字符串和apropos命令相同
-f 和whatis相同

然后我们通过man ls命令来详细分析下man page中的内容
[plain]  view plain copy
  1. [root@localhost ~]# man ls  
  2. LS(1)                            User Commands                           LS(1)  
  3.   
  4.   
  5. NAME  
  6.        ls - list directory contents  
  7.   
  8.   
  9. SYNOPSIS  
  10.        ls [OPTION]... [FILE]...  
  11.   
  12.   
  13. DESCRIPTION  
  14.        List  information  about  the FILEs (the current directory by  
  15.        default).  Sort entries alphabetically if none  of  -cftuvSUX  
  16.        nor --sort.  
  17.   
  18.   
  19.        Mandatory  arguments  to long options are mandatory for short  
  20.        options too.  
  21.   
  22.   
  23.        -a, --all  
  24.               do not ignore entries starting with .  
  25.   
  26.   
  27.        -A, --almost-all  
  28.               do not list implied . and ..  
  29. ...中间省略  
  30. AUTHOR  
  31.        Written by Richard Stallman and David MacKenzie.  
  32.   
  33.   
  34. REPORTING BUGS  
  35.        Report bugs to <bug-coreutils@gnu.org>.  
  36.   
  37.   
  38. COPYRIGHT  
  39.        Copyright © 2006 Free Software Foundation, Inc.  
  40.        This is free software.  You may  redistribute  copies  of  it  
  41.        under   the   terms   of   the  GNU  General  Public  License  
  42.        <http://www.gnu.org/licenses/gpl.html>.   There  is  NO  WAR-  
  43.        RANTY, to the extent permitted by law.  
  44.   
  45.   
  46. SEE ALSO  
  47.        The full documentation for ls is maintained as a Texinfo man-  
  48.        ual.  If the info and ls programs are properly  installed  at  
  49.        your site, the command  
  50.   
  51.   
  52.               info ls  
  53.   
  54.   
  55.        should give you access to the complete manual.  
  56.   
  57.   
  58. ls 5.97                          February 2010                           LS(1)  

这里可以看到,info ls可以给出详细描述


首先会看到NAME,COPYRIGHT等每一部分的title,具体代表含义参照以下
[plain]  view plain copy
  1. NAME        名字,简单的命令是用来做什么的  
  2. SYNOPSIS    简短的指令使用语法  
  3. DESCRIPTION 详细的描述命令的使用方法  
  4. OPTIONS     针对SYNOPSIS,进行详细的阐述  
  5. COMMANDS    执行的时候可下达的命令  
  6. FILES       指令相关的文件  
  7. SEE ALSO    和这个指令相关的命令  
  8. EXAMPLE     范例  
  9. BUGS        尚存在的漏洞  
  10. COPYRIGHT   版权信息  
  11. REPORTING BUGS  发现Bug可以上传的邮箱  
  12. AUTHOR      作者  

然后,又会看到LS(1)后面跟了一个1,这个数字也是有特定含义的
[plain]  view plain copy
  1. 1   指令或者可执行文档  
  2. 2   内核可调用的函数  
  3. 3   常用函数库  
  4. 4   档案说明  
  5. 5   档案格式  
  6. 6   游戏  
  7. 7   linux系统的说明性内容  
  8. 8   root可用的管理命名  
  9. 9   和内核相关的文件  

在man页中如何翻页,查找
箭头上下 上下行切换
Home/End 到第一页、最后一页
/String 查找一个字符串,n下一个查找到的结果,N上一个
q 结束这次
何时用man命令
我的心得是:这个命令基本不熟悉,需要详细的去看看自己想要的功能如何使用的时候,一般顺序是NAME-SYNOPSIS-DESCRIPTION-EXAMPLE


2、--help
列出常用命名的常用选项
使用场合:知道这个命令的使用领域,和简单使用方法,只是不熟悉某些选项
[plain]  view plain copy
  1. [root@localhost ~]# file --help  
  2. Usage: file [OPTION]... [FILE]...  
  3. Determine file type of FILEs.  
  4.   
  5.   -m, --magic-file LIST      use LIST as a colon-separated list of magic  
  6.                                number files  
  7.   -z, --uncompress           try to look inside compressed files  
  8.   -b, --brief                do not prepend filenames to output lines  
  9.   -c, --checking-printout    print the parsed form of the magic file, use in  
  10.                                conjunction with -m to debug a new magic file  
  11.                                before installing it  
  12.   -f, --files-from FILE      read the filenames to be examined from FILE  
  13.   -F, --separator string     use string as separator instead of `:'  
  14.   -i, --mime                 output mime type strings  
  15.   -k, --keep-going           don't stop at the first match  
  16.   -L, --dereference          causes symlinks to be followed  
  17.   -n, --no-buffer            do not buffer output  
  18.   -N, --no-pad               do not pad output  
  19.   -p, --preserve-date        preserve access times on files  
  20.   -r, --raw                  don't translate unprintable chars to \ooo  
  21.   -s, --special-files        treat special (block/char devices) files as  
  22.                              ordinary ones  
  23.       --help                 display this help and exit  
  24.       --version              output version information and exit  


3、whatis

查找whatis的数据库,寻找关键字的描述信息。在我们学会了man之后,可以直接man whatis来看信息

使用场合:我们想知道这个命令使用来干嘛的,或者我们想知道这个命令的种类

[plain]  view plain copy
  1. [root@localhost ~]# whatis ls  
  2. ls                   (1)  - list directory contents  
  3. ls                   (1p)  - list directory contents  
  4. [root@localhost ~]# whatis CD  
  5. cd                   (1p)  - change the working directory  
  6. cd [builtins]        (1)  - bash built-in commands, see bash(1)  

4、help
查看shell内建指令的帮助信息,例如我们cd就是一个bash内建指令
[plain]  view plain copy
  1. [root@localhost ~]# cd --help  
  2. bash: cd: --: invalid option  
  3. cd: usage: cd [-L|-P] [dir]  
  4. [root@localhost ~]# help cd  
  5. cd: cd [-L|-P] [dir]  
  6.     Change the current directory to DIR.  The variable $HOME is the  
  7.     default DIR.  The variable CDPATH defines the search path for  
  8.     the directory containing DIR.  Alternative directory names in CDPATH  
  9.     are separated by a colon (:).  A null directory name is the same as  
  10.     the current directory, i.e. `.'.  If DIR begins with a slash (/),  
  11.     then CDPATH is not used.  If the directory is not found, and the  
  12.     shell option `cdable_vars' is set, then try the word as a variable  
  13.     name.  If that variable has a value, then cd to the value of that  
  14.     variable.  The -P option says to use the physical directory structure  
  15.     instead of following symbolic links; the -L option forces symbolic links  
  16.     to be followed.  

其他的内建指令
[plain]  view plain copy
  1. alias, bg, bind, break, builtin, cd, command,  
  2.        compgen, complete,  continue,  declare,  dirs,  disown,  echo,  
  3.        enable, eval, exec, exit, export, fc, fg, getopts, hash, help,  
  4.        history, jobs, kill, let, local, logout, popd, printf,  pushd,  
  5.        pwd,  read,  readonly, return, set, shift, shopt, source, sus-  
  6.        pend, test, times, trap, type, typeset,  ulimit,  umask,  una-  
  7.        lias, unset, wait  
  8.