Deep analysis of Linux built-in commands and external commands

Source: Internet
Author: User
Tags builtin


Internal commands are transferred into memory when the system is started, and are resident memory, so the execution efficiency is high.
The external command is the software function of the system, which is read into memory from the hard disk when the user needs it.
Type can be used to determine whether a command is a built-in command

Type:usage:type [-AFPTP] name [name ...]
[Root@linuxeye ~]# Type type
Type is a shell builtin
[Root@linuxeye ~]# type-p type
[Root@linuxeye ~]# type-t type
Builtin
[Root@linuxeye ~]# Type type
Type is a shell builtin
[Root@linuxeye ~]# type-t type
Builtin
[Root@linuxeye ~]# type pwd
PWD is a shell builtin
[Root@linuxeye ~]# Type Whiptail
Whiptail Is/usr/bin/whiptail
[Root@linuxeye ~]# type-t Whiptail
File
Enable to view both internal commands and to determine whether internal commands

[Root@linuxeye ~]# enable-a #查看内部命令
[Root@linuxeye ~]# Enable Whiptail #非内部命令
-bash:enable:whiptail:not a shell builtin
[Root@linuxeye ~]# enable PWD #是内部命令
Internal command user input when the system calls the speed, not the built-in command, the system will read the environment variable file. bash_profile,/etc/profile to find path paths.

Then in the invocation of the command, some historical commands are used, and there will be in the hash table, and when you enter the command again it will be a process called.

hash--> built-in Command-->path command calls should actually be such a process.

[Root@linuxeye ~]# type pwd
PWD is a shell builtin
[Root@linuxeye ~]# type Cat
Cat Is/usr/bin/cat
[Root@linuxeye ~]# pwd
/root
[Root@linuxeye ~]# ls linuxeye*
Linuxeye.pem Linuxeye.txt
[Root@linuxeye ~]# Cat Linuxeye.txt
Linuxeye
[Root@linuxeye ~]# hash-l #显示hash表
Builtin Hash-p/usr/bin/cat Cat
Builtin hash-p/usr/bin/ls ls
[Root@linuxeye ~]# type Cat
Cat is hashed (/USR/BIN/CAT)
[Root@linuxeye ~]# hash-r #清除hash表
[Root@linuxeye ~]# type Cat
Cat Is/usr/bin/cat
From the above operation can be seen. The hash table does not store system-built commands.

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.