Detailed linux command execution

1, execute the command
after command input Enter
drew shell program or executable program code is found, type the corresponding command, and its later stages, submitted to the kernel to allocate resources to run it up.
Enforceable in the shell command has two categories:
internal command: the shell comes within the integrated command
help you can view a list of internal commands

[root@centos7 ~]# 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 -anrw [filename] or >
 (( expression ))                                                if COMMANDS; then COMMANDS; [ elif COMMANDS; then COMMANDS; >
 . filename [arguments]                                          jobs [-lnprs] [jobspec ...] or jobs -x command [args]
 :                                                               kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... o>
 [ arg... ]                                                      let arg [arg ...]
 [[ expression ]]                                                local [option] name[=value] ...
 alias [-p] [name[=value] ... ]                                  logout [n]
 bg [job_spec ...]                                               mapfile [-n count] [-O origin] [-s count] [-t] [-u fd] [-C c>
 bind [-lpvsPVS] [-m keymap] [-f filename] [-q name] [-u name]>  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]...) COMMANDS ;;]... esac      read [-ers] [-a array] [-d delim] [-i text] [-n nchars] [-N >
 cd [-L|[-P [-e]]] [dir]                                         readarray [-n count] [-O origin] [-s count] [-t] [-u fd] [-C>
 command [-pVv] command [arg ...]                                readonly [-aAf] [name[=value] ...] or readonly -p
 compgen [-abcdefgjksuv] [-o option]  [-A action] [-G globpat]>  return [n]
 complete [-abcdefgjksuv] [-pr] [-DE] [-o option] [-A action] >  select NAME [in WORDS ... ;] do COMMANDS; done
 compopt [-o|+o option] [-DE] [name ...]                         set [-abefhkmnptuvxBCHP] [-o option-name] [--] [arg ...]
 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 ...]] [redirection .>  true
 exit [n]                                                        type [-afptP] name [name ...]
 export [-fn] [name[=value] ...] or export -p                    typeset [-aAfFgilrtux] [-p] name[=value] ...
 false                                                           ulimit [-SHacdefilmnpqrstuvx] [limit]
 fc [-e ename] [-lnr] [first] [last] or fc -s [pat=rep] [comma>  umask [-p] [-S] [mode]
 fg [job_spec]                                                   unalias [-a] name [name ...]
 for NAME [in WORDS ... ] ; do COMMANDS; done                    unset [-f] [-v] [name ...]
 for (( exp1; exp2; exp3 )); do COMMANDS; done                   until COMMANDS; do COMMANDS; done
 function name { COMMANDS ; } or name () { COMMANDS ; }          variables - Names and meanings of some shell variables
 getopts optstring name [arg]                                    wait [id]
 hash [-lr] [-p pathname] [-dt] [name ...]                       while COMMANDS; do COMMANDS; done
 help [-dms] [pattern ...]                                       { COMMANDS ; }

enable can also view a list of commands

[root@centos7 ~]# enable
enable .
enable :
enable [
enable alias
enable bg
enable bind
enable break
enable builtin
enable caller
enable cd
enable command
enable compgen
enable complete
enable compopt
enable continue
enable declare
enable dirs
enable disown
enable echo
enable enable
enable eval
enable exec
enable exit
enable export
enable false
enable fc
enable fg
enable getopts
enable hash
enable help
enable history
enable jobs
enable kill
enable let
enable local
enable logout
enable mapfile
enable popd
enable printf
enable pushd
enable pwd
enable read
enable readarray
enable readonly
enable return
enable set
enable shift

External commands: a corresponding executable file path in the file system
view path of the command
a, wheris

[root@centos7 ~]# whereis ls     #多了帮助文档,更加详细
ls: /usr/bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz

二、which -a

[root@centos7 ~]# which -a ls
alias ls='ls --color=auto'
    /usr/bin/ls

If it is determined command is an internal command or external command
command: type

实例:[root@centos7 ~]# type pwd
pwd is a shell builtin            #内部命令
[root@centos7 ~]# type hostname
hostname is /usr/bin/hostname      #外部命令表示为一个文件

It is also possible both external command is a command internal commands, so you can view

[root@centos7 ~]# type -a pwd
pwd is a shell builtin
pwd is /usr/bin/pwd

So the question is, input command is a command to perform an internal or external command it?
A command execution procedure is this:
look at is not an internal command (internal command execution is faster), the internal command a higher priority, and then to check the hash table (the recording path of the external command), if found, to find the then execute. If you can not find the path to this command in the disk, you will find in the following manner.
External Command process of finding the path (first execution)

[root@centos7 bin]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

When we re-execute a command. When the confirmation is not an internal command, as will be looking for more of an external command file directory, find (find and stopped) on the implementation, such as this:

[root@centos7 bin]# type hostname
hostname is /usr/bin/hostname     #在/usr/bin 下面找到

If no error is reported.

[root@centos7 bin]# lsls
bash: lsls: command not found...     #命令输入有误

After the command to find this, it will be the path of the command recorded in the hash table, re-use, can be quickly implemented to improve the command call rate.
Example:

root@centos7 bin]# hash
hits    command
   2    /usr/bin/whereis
   2    /usr/bin/man
   3    /usr/bin/ls

View command again:

[root@centos7 bin]# type whereis
whereis is hashed (/usr/bin/whereis)
[root@centos7 bin]# type ifconfig
ifconfig is hashed (/usr/sbin/ifconfig)

Clear the cache hash

[root@centos7 etc]# hash
hits    command
   6    /usr/sbin/ifconfig
   1    /usr/bin/rm
   1    /usr/bin/cat
   9    /usr/bin/whereis
   3    /usr/bin/cp
   2    /usr/bin/man
   4    /usr/bin/ls
   1    /usr/bin/clear
[root@centos7 etc]# hash -r
[root@centos7 etc]# hash
hash: hash table empty

Guess you like

Origin blog.51cto.com/11620628/2430428