Linux 帮助命令

实验楼 Linux 基础学习笔记

Posted by lijian on September 17, 2017

文章 实验楼实验笔记

内建命令和外部命令

内建命令实际上是 shell 程序的一部分,其中包含的是一些比较简单的 Linux 系统命令,这些命令是写在bash源码的builtins里面的,由 shell 程序识别并在 shell 程序内部完成运行,通常在 Linux 系统加载运行时 shell 就被加载并驻留在系统内存中。而且解析内部命令 shell 不需要创建子进程,因此其执行速度比外部命令快。比如:history、cd、exit 等等

外部命令是 Linux 系统中的实用程序部分,因为实用程序的功能通常都比较强大,所以其包含的程序量也会很大,在系统加载时并不随系统一起被加载到内存中,而是在需要时才将其调入内存。虽然其不包含在 shell 中,但是其命令执行过程是由 shell 程序控制的。外部命令是在 Bash 之外额外安装的,通常放在/bin,/usr/bin,/sbin,/usr/sbin等等。比如:ls、vi等。

  • 使用type 命令可以区分是内建命令还是外部命令
      ~ type vi
    vi is /usr/bin/vi
      ~ type ls
    ls is an alias for ls -G
      ~ type cat
    cat is /bin/cat
      ~ type vim
    vim is /usr/bin/vim
      ~ type exit
    exit is a shell builtin
    

help 命令

首先通过 bash 进入 bash 环境

  ~ bash
bash-3.2$ help vi
bash: help: no help topics match `vi'.  Try `help help' or `man -k vi' or `info vi'.
bash-3.2$
bash-3.2$
bash-3.2$ help exit
exit: exit [n]
    Exit the shell with a status of N.  If N is omitted, the exit status
    is that of the last command executed.
bash-3.2$
bash-3.2$
bash-3.2$ exit
exit
  ~ ls --help
ls: illegal option -- -
usage: ls [-ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1] [file ...]
  • 结果说明 help 命令是用于显示 shell 内建命令的简要帮助信息。帮助信息中显示有该命令的简要说明以及一些参数的使用以及说明,一定记住 help 命令只能用于显示内建命令的帮助信息。通过前面我们知道 ls 是外部命令,所以使用help 会有问题,同样我们对于 exit 命令使用help 就没有问题。 对于外部命令想使用help , 外部命令基本上都有一个参数–help,这样就可以得到相应的帮助.

man 命令

man ls

man 命令得到的内容比用 help 更多更详细,而且 man 没有内建与外部命令的区分,因为 man 工具是显示系统手册页中的内容,也就是一本电子版的字典,这些内容大多数都是对命令的解释信息,还有一些相关的描述。通过查看系统文档中的 man 也可以得到程序的更多相关信息和 Linux 的更多特性。

info 命令

info ls

info 命令显示的内容比 man 命令更加详细

关键点

  • help 用于显示内建命令的关键信息
  • man 命令用于显示命令的帮助文档
  • info 命令显示更加详细的文档信息