Home >Operation and Maintenance >Linux Operation and Maintenance >There are several types of Linux commands

There are several types of Linux commands

青灯夜游
青灯夜游Original
2023-02-08 11:26:101931browse

Linux commands have two types: 1. Internal commands (shell commands), which are recognized by the shell program and run inside the shell program; they are transferred into the memory when the system starts and are resident in the memory. So the execution efficiency is high. 2. External commands (file system commands) are programs outside of the bash shell and are software functions of the system. They are read from the hard disk into the memory when the user needs them.

There are several types of Linux commands

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

Two types of Linux commands

Linux commands are divided into internal commands (built-in commands) and external commands, internal commands and external commands The command functions are basically the same, but there are some subtle differences.

The built-in commands are transferred into the memory when the system starts. They are resident in the memory, so the execution efficiency is high. The external command is a software function of the system, which is read into the memory from the hard disk when the user needs it.

External commands

External commands are also called file system commands. They are programs outside the bash shell and are not part of the shell. External commands are typically located in /bin, /usr/bin, /sbin, or /usr/sbin. External commands are the utility part of the Linux system. Because the functions of utility programs are usually relatively powerful, the amount of programs they contain will also be large. When the system is loaded, they are not loaded into the memory together with the system, but when needed. Only then will it be called into memory.

Usually the entity of the external command is not included in the shell, but its command execution process is controlled by the shell program. The shell program manages the path search, loading and storage of external command execution, and controls the execution of commands. External commands are installed additionally outside of bash, usually placed in /bin, /usr/bin, /sbin, /usr/sbin... etc. You can use the "echo

$PATH" command to view the storage path of external commands, such as: ls, vi, etc.

Built-in commands

The internal commands are actually part of the shell program, which contain some relatively simple Linux system commands, which are recognized by the shell program and executed in the shell program. The shell program completes the operation internally. Usually when the Linux system is loaded and run, the shell is loaded and resides in the system memory.

Internal commands are written in the bash source code, and their execution speed is faster than external commands, because parsing the internal command shell does not require the creation of a child process. For example: exit, history, cd, echo, etc.

Explanation

The pwd command is a special command with two versions, one is a built-in command and the other is an external command.

Summary

External commands will create a child process containing a new environment, but built-in commands will not. In comparison, external commands are more expensive to use, so built-in commands are more efficient and will not be affected by environmental changes.

Distinguish between built-in commands and external commands

Syntax

type command

Case

We use the type command to check whether the cd command is an internal command or an external command. The specific command is as follows:

type cd

After running, the terminal output is as follows:

There are several types of Linux commands

We see that the output cd is a built-in command. Now, we use the type command again to check whether the ps command is a built-in command or an external command. The specific command is as follows:

type ps

After running, The terminal output is as follows:

There are several types of Linux commands

#We see that the position of the ps command is output, that is, it indicates that the ps command is an external command.

Related recommendations: "Linux Video Tutorial"

The above is the detailed content of There are several types of Linux commands. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn