标签:版本 root 方便 names 公式 exe return obs 哈希
为什么在提示符下命令可以被执行呢?
输入命令后回车,提请shell程序找到键入命令所对应的可执行程序或代码,并由其分析后提交给内核分配资源将其运行起来
shell本身也是一个程序,只不过在用户登录过程中已经加载到内存中了。
对shell可以理解为一个工具箱,集成了很多很多的小工具
shell程序对应磁盘文件
[03:05:41 root@C8[ ~]#ll /bin/bash
-rwxr-xr-x. 1 root root 1219248 Nov 8 11:30 /bin/bash
bash里集成的小工具被称为内部命令,所谓的内外是以属不属于bash来判断的
type COMMAND
[03:12:01 root@C8[ ~]#type ll
ll is aliased to `ls -l --color=auto‘ #这是一个别名
[03:49:43 root@C8[ ~]#type hostname
hostname is /usr/bin/hostname #外部命令并显示路径
[03:50:03 root@C8[ ~]#type echo
echo is a shell builtin #内部命令 shell 建立在里边
当用户输入一个命令,系统先判断是否是内部命令,如果不是内部命令,则按照系统环境变量的地址去磁盘上寻找外部命令
搜索外部命令的次序在$PATH中,如果找到了,就加载到内存中执行。
[03:50:16 root@C8[ ~]#echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
内部命令随bash已经加载在内存中,执行效率最高。
外部命硬在硬盘上,每次需要找到再执行,这样执行效率很低。
系统策略可以将不久前执行过的命令路径记录在内存中,方便下次使用。
这种行为叫做hash
[03:59:10 root@C8[ ~]#type hostname
hostname is hashed (/usr/bin/hostname)
hits 代表命令被执行了几次
[03:59:23 root@C8[ ~]#hash
hits command
2 /usr/bin/hostname
1 /usr/bin/lscpu
1 /usr/sbin/runlevel
1 /usr/bin/ls
2 /usr/bin/free
help即是帮助,又显示出所有的内部命令
enable 也可以显示内部命令
[04:16:25 root@C8[ ~]#help
GNU bash, version 4.4.19(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 history -anrw>
(( expression )) if COMMANDS; then COMMANDS; [ elif COMMANDS; >
. filename [arguments] jobs [-lnprs] [jobspec ...] or jobs -x comman>
: kill [-s sigspec | -n signum | -sigspec] pid >
[ arg... ] let arg [arg ...]
[[ expression ]] local [option] name[=value] ...
alias [-p] [name[=value] ... ] logout [n]
bg [job_spec ...] mapfile [-d delim] [-n count] [-O origin] [-s>
bind [-lpsvPSVX] [-m keymap] [-f filename] [-q> 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> read [-ers] [-a array] [-d delim] [-i text] [>
cd [-L|[-P [-e]] [-@]] [dir] readarray [-n count] [-O origin] [-s count] [>
command [-pVv] command [arg ...] readonly [-aAf] [name[=value] ...] or readonl>
compgen [-abcdefgjksuv] [-o option] [-A action> return [n]
complete [-abcdefgjksuv] [-pr] [-DE] [-o optio> select NAME [in WORDS ... ;] do COMMANDS; do>
compopt [-o|+o option] [-DE] [name ...] set [-abefhkmnptuvxBCHP] [-o option-name] [-->
continue [n] shift [n]
coproc [NAME] command [redirections] shopt [-pqsu] [-o] [optname ...]
declare [-aAfFgilnrtux] [-p] [name[=value] ...> source filename [arguments]
dirs [-clpv] [+N] [-N] suspend [-f]
disown [-h] [-ar] [jobspec ... | pid ...] 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 export -p typeset [-aAfFgilnrtux] [-p] name[=value] ...
false ulimit [-SHabcdefiklmnpqrstuvxPT] [limit]
fc [-e ename] [-lnr] [first] [last] or fc -s [> umask [-p] [-S] [mode]
fg [job_spec] unalias [-a] name [name ...]
for NAME [in WORDS ... ] ; do COMMANDS; done unset [-f] [-v] [-n] [name ...]
for (( exp1; exp2; exp3 )); do COMMANDS; done until COMMANDS; do COMMANDS; done
function name { COMMANDS ; } or name () { COMM> variables - Names and meanings of some shell >
getopts optstring name [arg] wait [-n] [id ...]
hash [-lr] [-p pathname] [-dt] [name ...] while COMMANDS; do COMMANDS; done
help [-dms] [pattern ...] { COMMANDS ; }
哈希hash
应用举例:
MD5
标签:版本 root 方便 names 公式 exe return obs 哈希
原文地址:https://www.cnblogs.com/bpzblog/p/12617104.html