Home > Article > Operation and Maintenance > Basic command classification of LInux system operation explanation
Execution process of command
When the system executes an external command for the first time The hash cache table is empty. The system will first search for the command from the PTAH path. After finding it, the path will be added to the Hasa cache. When the command is executed again, it will be executed directly from the hash path. If it exists, it will be executed directly. If it does not exist, it will be executed directly. The search will continue from the path under PATH, and the Hash table can improve the calling rate of the command.
Priority of command
alias -------------------------- ----------------Alias
builtin-------------------------------- -Internal command
ˆ ˆhash-------------------------Cache table
ˆ ˆˆˆˆhash-------------------------- ----Executable program or script (external command)
Internal command and external command
The internal command is the shell’s own
External commands are installed by default when installing the system, and have corresponding paths in the file system
Check whether the command is an internal command or an external commandtype [commnd ]
[root@centos6 ~]# type cat #判断cat命令,外部命令显示文件路径 cat is /bin/cat [root@centos6 ~]# type cd #判断cd命令 cd is a shell builtin
The named alias is only valid in the current process
If you want it to be permanently valid, it must be defined in the configuration file
Only for the current user: ~/.bashrc
Valid for all users: /etc/bashrc
View all aliases in the processalias
[root@centos6 ~]#alias alias cp='cp -i' alias l.='ls -d .* --color=auto' alias ll='ls -l --color=auto' alias ls='ls --color=auto' ......
Define aliasalias NAME="VALUE"
[root@centos6 ~]#alias aubin=cat [root@centos6 ~]#aubin test hello world
Delete alias
[root@centos6 ~]#unalias aubin [root@centos6 ~]#aubin test -bash: aubin: command not found
Define the alias that is permanently effective for the current user
[root@centos6 ~]#vim .bashrc # .bashrc # User specific aliases and functions alias rm='rm -i' alias cp='cp -i' alias mv='mv -i' alias aubin=cat # <<<-----此处定义别名 # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi [root@centos6 ~]#. .bash #立即生效
Definition The alias that is effective for the specified user
[root@centos6 ~]#cd ~ li [root@centos6 li]#vim .bashrc #编辑用户目录下的.bashrc
DefinitionAll usersEffective aliases
[root@centos6 ~]#vim /etc/bashrc alias aubin=cat # <<<-----加入定义别名 [root@centos6 ~]#. /etc/bashrc #立即生效
The shell program finds the executable program or code corresponding to the typed command. After analysis by the shell, it is submitted to the kernel to allocate resources and run it.
View all internal commands
[root@centos6 ~]#help
[root@centos6 ~]#enable enable . enable : enable [ enable alias enable bg enable bind ......
Disable and enable internal commandsenable
[root@centos6 li]#enable -n cd #禁用内部命令 [root@centos6 li]#enable cd #启用内部命令
Disable internal commandsInvalid
[root@centos6 li]#enable -n pwd [root@centos6 li]#enable -n #查看禁用的内部命令或如下图用help enable -n pwd
You can also check the disabled commands byhelp
【*# before the command ##Represents that the command has been used】
Disables the internal command
enable -n pwd can still be used
[root@centos6 li]#pwd /home/liUse
which to view the command The executable file
[root@centos6 li]#which pwd /bin/pwdWhen the internal command is disabled, continue to search the Hash table and
\(PATH. Until the /bin/pwd# is found in \)PATH according to the bash priority. ##'s executable file will run it.
[root@centos6 li]#enable -n enable -n cd enable -n pwd
Or use the
help command as shown above
<pre class="brush:php;toolbar:false">[root@centos6 ~]# hash
hits command
3 /usr/bin/cal
1 /usr/bin/yum</pre>
<pre class="brush:php;toolbar:false">[root@centos6 ~]# 查看详细的Hash表
[root@centos6 ~]#hash -l
builtin hash -p /bin/dd dd
builtin hash -p /usr/bin/yum yum</pre>
<pre class="brush:php;toolbar:false">[root@centos6 ~]#将cat定义一个别名存在hash表
[root@centos6 ~]#hash -p /bin/cat aubin
[root@centos6 ~]#aubin test
hello world</pre>
<pre class="brush:php;toolbar:false">[root@centos6 ~]#hash -t aubin
/bin/cat</pre>
<pre class="brush:php;toolbar:false">[root@centos6 ~]#hash -d aubin</pre>
<pre class="brush:php;toolbar:false">[root@centos6 ~]# hash -r</pre>
<pre class="brush:php;toolbar:false">[root@centos6 ~]# which cat #查看命令的路径,以第一个路径为准
/bin/cat
[root@centos6 ~]# which -a cat #查看命令所有路径,一个命令可能有多个路径
/bin/cat
/usr/local/bin/cat</pre>
[root@centos6 /]#which echo #列出命令的路径 /bin/echo
[root@centos6 /]#which cp #which列出文件路径会显示别名 alias cp='cp -i' /bin/cp [root@centos6 /]#which --skip-alias cp #列出文件路径而不显示别名 /bin/cp
[root@centos6 /]#which -a echo /bin/echo
[root@centos6 /]#whereis echo echo: /bin/echo /usr/share/man/man1/echo.1.gz /usr/share/man/man1p/echo.1p.gz
The above is the detailed content of Basic command classification of LInux system operation explanation. For more information, please follow other related articles on the PHP Chinese website!