Linux Learning within the build command and external commands detailed __linux

Source: Internet
Author: User
Tags builtin hash

Linux commands have internal commands (built-in commands) and external commands, internal commands and external command functions are basically the same, but their working mechanism varies widely. This article introduces the built-in commands and external commands.

I. Internal command (built-in command)

Internal commands, which are actually part of the shell program, contain some simpler Linux system commands that are identified by the shell program and run inside the shell, usually loaded and hosted in the system's memory when the Linux system loads the runtime. The internal command is written in the Bashy source code, and it executes faster than the external command because parsing the internal command shell does not require the creation of child processes. For example: Exit,history,cd,echo and so on.

So when an internal command is executed, it is searched in the memory and then executed.

Second, external orders

External commands are part of the utility in a Linux system, because the utility is usually powerful, so it contains a large number of programs, so the system is loaded without being loaded into memory with the system. The system is called to memory only when it is needed. Typically, an entity of an external command is not included in the shell, but its command execution process is controlled by the shell. The shell program manages the path lookup, loading and storage of the external command execution, and controls the execution of the command. External commands are installed outside of bash, usually in/bin,/usr/bin,/sbin,/usr/sbin ... Wait a minute. You can view the storage path of an external command through the echo $PATH command, such as LS, VI, and so on.

Iii. other relevant introductions to internal commands and external commands

1 How to distinguish between the two

The way to determine whether a command is an internal or external command is: Type command

[Root@localhoast ~]# type pwdpwd is a shell Builtin

[Root@localhoast ~]# type vimvim is/usr/bin/VI

The builtin displayed indicates that the command is an internal (built-in command), and that the command that shows the execution path is the external command.

2) The execution process of the two

The system is called from memory when the internal command is executed by the user, and the rate of the call is fast. When an external command is executed, the system will read the environment variable file. bash_profile,/etc/profile to find path path.

Then, in the invocation of the command, some external commands are used, and there is a hash table, and when you enter the command again, the call to it will be such a process.

hash--> built-in Command-->path command calls should actually be such a process. The hash has the highest precedence, then the internal command, and finally the external command.

[Root@localhost ~]# pwd

/root

[root@localhost ~]# ls

Anaconda-ks.cfg Install.log Install.log.syslog

[Root@localhost ~]# Hash-L

Show hash Table

Builtin Hash-p /bin/cat Cat

Builtin Hash-p /bin/ls ls

As can be seen from the hash table, the hash table does not store the system built-in commands.

Article source: Yun-Wei Tribe

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.