Precedence comparison of aliases, internal commands, external commands, and hash cache table system calls in Linux

Source: Internet
Author: User
Tags aliases

Priority comparison of aliases, internal commands, external commands, and hash cache tables in Linux systems


In our usual use of the Linux system to execute a variety of commands, we will find that the command in the execution process will distinguish between which priority execution, which second execution, here we do a test to prove it.

Aliases: Use the alias command to set the alias of the command.


Internal command: The internal command is in memory when the system is started.


External command: The external command is the system's software function as a file that the user needs to read into memory from the hard disk.


Hash Cache table: Linux system will have a hash cache table, when you just open this hash table is empty, every time you execute a command, the hash table will record the path of this command, equivalent to the cache.


So from the above we can draw: internal command > External command

Internal Command >hash table


Next, let's compare the relationship between aliases and internal commands:


[[email protected]] #type CD to make sure the CD is an internal command

CD is a shell builtin

[[email protected]] #type touch to make sure touch is an external command

Touch Is/bin/touch

[[email protected]] #alias Cd=touch to touch to take the individual name CD

[[email protected]] #cd run this command

touch:missing file operand

Try ' Touch--help ' for more information. System error, let you see more about touch help

[Email protected]]#


By running a command with the same name, it proves that the system called the alias first.


So:

Aliases > Internal commands


And then we'll compare the relationship between the hash table and the external command:


[[email protected]] #type who view who's address

Who is/usr/bin/who

[[email protected]] #cp/usr/bin/who/usr/local/bin/copy a new WHO

[[email protected]] #ls-l/usr/bin/who/usr/local/bin/who take a look at two other who, except for location.

-rwxr-xr-x. 1 root root 48952 Mar 02:52/usr/bin/who

-rwxr-xr-x. 1 root root 48952 11:25/usr/local/bin/who

[[email protected]] #who use once to get it into the hash cache table

Root PTS/1 2017-05-21 11:22 (172.17.250.52)

Root PTS/2 2017-05-21 11:22 (172.17.250.52)

Root tty1 2017-05-21 11:22 (: 0)

[[email protected]] #type who looks at which address it uses

Who is hashed (/usr/local/bin/who)

[[email protected]] #rm/usr/local/bin/who Delete that address

Rm:remove regular file '/usr/local/bin/who '? Y

[[email protected]] #who re-use

-bash:/usr/local/bin/who:no Such file or directory cannot find directory error

[Email protected]]#


This can not find the directory error also shows that the execution of this command is to find the hash cache table record address, indicating that the hash cache tables in the command execution is more priority than the external command.

Also proves: internal command >hash> external command


Sum up:

Command execution priority: aliases > Internal commands >hash> external commands


This article is from the "11986114" blog, please be sure to keep this source http://11996114.blog.51cto.com/11986114/1927874

Precedence comparison of aliases, internal commands, external commands, and hash cache table system calls in Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.