欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

内部命令和外部命令帮助

程序员文章站 2022-05-29 10:33:43
    查看内部命令和外部命令帮助 一、内部命令   可以用type来判断该命令是内部命令还是外部命令,type后加要查看的命令. 示例写法:type enable   有的命令既有内部命令也有外部命令但是系统会优先使用 ......

    查看内部命令和外部命令帮助

一、内部命令

  可以用type来判断该命令是内部命令还是外部命令,type后加要查看的命令.

示例写法:type enable

[10:52:18 root@centos ~]#type enable
enable is a shell builtin  

  有的命令既有内部命令也有外部命令但是系统会优先使用内部命令。
例如:type echo ,查看到的是内部命令,但是加上 -a系统会显示出他的外部命令路径。

[11:32:59 root@centos ~]#type echo
echo is a shell builtin
[11:33:18 root@centos ~]#type -a echo
echo is a shell builtin
echo is /usr/bin/echo  

help查看全部内部命令的简单说明

[09:47:49 root@centos ~]#help
gnu bash, version 4.2.46(2)-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 history>
 (( expression ))                           if commands; then commands; [ elif comm>
 . filename [arguments]                     jobs [-lnprs] [jobspec ...] or jobs -x >
 :                                          kill [-s sigspec | -n signum | -sigspec>
 [ arg... ]                                 let arg [arg ...]
 [[ expression ]]                           local [option] name[=value] ...
 alias [-p] [name[=value] ... ]             logout [n]
 bg [job_spec ...]                          mapfile [-n count] [-o origin] [-s coun>
 bind [-lpvspvs] [-m keymap] [-f filename>  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]...) co>  read [-ers] [-a array] [-d delim] [-i t>
 cd [-l|[-p [-e]]] [dir]                    readarray [-n count] [-o origin] [-s co>
 command [-pvv] command [arg ...]           readonly [-aaf] [name[=value] ...] or r>
 compgen [-abcdefgjksuv] [-o option]  [-a>  return [n]
 complete [-abcdefgjksuv] [-pr] [-de] [-o>  select name [in words ... ;] do command>
 compopt [-o|+o option] [-de] [name ...]    set [-abefhkmnptuvxbchp] [-o option-nam>
 continue [n]                               shift [n]
 coproc [name] command [redirections]       shopt [-pqsu] [-o] [optname ...]
 declare [-aaffgilrtux] [-p] [name[=value>  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] [name >  times
 eval [arg ...]                             trap [-lp] [[arg] signal_spec ...]
 exec [-cl] [-a name] [command [arguments>  true
 exit [n]                                   type [-afptp] name [name ...]
 export [-fn] [name[=value] ...] or expor>  typeset [-aaffgilrtux] [-p] name[=value>
 false                                      ulimit [-shacdefilmnpqrstuvx] [limit]
 fc [-e ename] [-lnr] [first] [last] or f>  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 commands;>  until commands; do commands; done
 function name { commands ; } or name () >  variables - names and meanings of some >
 getopts optstring name [arg]               wait [id]
 hash [-lr] [-p pathname] [-dt] [name ...>  while commands; do commands; done
 help [-dms] [pattern ...]                  { commands ; }  

查看某一个内部命令详细说明:

示例写法:help enable
help后面加上要查看的命令。

[10:45:50 root@centos ~]#help enable
enable: enable [-a] [-dnps] [-f filename] [name ...]
    enable and disable shell builtins.
    
    enables and disables builtin shell commands.  disabling allows you to
    execute a disk command which has the same name as a shell builtin
    without using a full pathname.
    
    options:
      -a    print a list of builtins showing whether or not each is enabled
      -n    disable each name or display a list of disabled builtins
      -p    print the list of builtins in a reusable format
      -s    print only the names of posix `special' builtins
    
    options controlling dynamic loading:
      -f    load builtin name from shared object filename
      -d    remove a builtin loaded with -f
    
    without options, each name is enabled.
    
    to use the `test' found in $path instead of the shell builtin
    version, type `enable -n test'.
    
    exit status:
    returns success unless name is not a shell builtin or an error occurs.  

echo用法及原理

echo可以将你输入的内容进行显示,可以加参数,显示参数标准输出显示。并且自动换新行。

-n: 加上-n就是不换行

-e:启用反斜杠转义解释 示例:echo -e '\a' 警报声 '\a' 加引号。

  用法示例:sleep 10;echo -e '\a' 休眠10秒,结束后警报声提醒

-e:禁用反斜杠转义解释

范例:echo的help使用方法

echo内部命令帮助查看:
示例写法:help echo

[11:33:21 root@centos ~]#help echo
echo: echo [-nee] [arg ...]
    write arguments to the standard output.
    
    display the args on the standard output followed by a newline.
    
    options:
      -n    do not append a newline
      -e    enable interpretation of the following backslash escapes
      -e    explicitly suppress interpretation of backslash escapes
    
    `echo' interprets the following backslash-escaped characters:
      \a    alert (bell)  警报声提醒
      \b    backspace
      \c    suppress further output 压缩之后的输出 压缩掉echo的换行
      \e    escape character
      \f    form feed
      \n    new line  换新行  本身echo就带有换行,再加\n表示换两行。
      \r    carriage return
      \t    horizontal tab
      \v    vertical tab
      \\    backslash
      \0nnn the character whose ascii code is nnn (octal).  nnn can be
        0 to 3 octal digits
      \xhh  the eight-bit character whose value is hh (hexadecimal).  hh
        can be one or two hex digits
    
    exit status:
    returns success unless a write error occurs. 

二、外部命令

带有路径的都是外部命令。
示例:passwd --help

[13:55:39 root@centos ~]#type passwd
passwd is hashed (/usr/bin/passwd)  
[13:01:45 root@centos ~]#passwd --help
usage: passwd [option...] <accountname>
  -k, --keep-tokens       keep non-expired authentication tokens
  -d, --delete            delete the password for the named account (root only)
  -l, --lock              lock the password for the named account (root only)
  -u, --unlock            unlock the password for the named account (root only)
  -e, --expire            expire the password for the named account (root only)
  -f, --force             force operation
  -x, --maximum=days      maximum password lifetime (root only)
  -n, --minimum=days      minimum password lifetime (root only)
  -w, --warning=days      number of days warning users receives before password
                          expiration (root only)
  -i, --inactive=days     number of days after password expiration when an account
                          becomes disabled (root only)
  -s, --status            report password status on the named account (root only)
  --stdin                 read new tokens from stdin (root only)

help options:
  -?, --help              show this help message
  --usage                 display brief usage message  

echo外部命令查看帮助:
示例写法:/bin/echo --help

[12:25:14 root@centos ~]#/bin/echo --help
usage: /bin/echo [short-option]... [string]...
  or:  /bin/echo long-option
echo the string(s) to standard output.

  -n             do not output the trailing newline
  -e             enable interpretation of backslash escapes
  -e             disable interpretation of backslash escapes (default)
      --help     display this help and exit
      --version  output version information and exit

if -e is in effect, the following sequences are recognized:

  \\      backslash
  \a      alert (bel)
  \b      backspace
  \c      produce no further output
  \e      escape
  \f      form feed
  \n      new line
  \r      carriage return
  \t      horizontal tab
  \v      vertical tab
  \0nnn   byte with octal value nnn (1 to 3 digits)
  \xhh    byte with hexadecimal value hh (1 to 2 digits)

note: your shell may have its own version of echo, which usually supersedes
the version described here.  please refer to your shell's documentation
for details about the options it supports.

gnu coreutils online help: <http://www.gnu.org/software/coreutils/>
for complete documentation, run: info coreutils 'echo invocation'  

echo以上的写法查看到的帮助用法是相同的,但是帮助内容不一样,仅供参考。) 内部命令和外部命令帮助

   可能写的有点乱,第三次写还有点不适应。