The command mechanism of Linux

Source: Internet
Author: User
Tags aliases

Command format

COMMAND [OPTIONS ...] [ARGUMENTS ...]
Options: One or some of the features used to enable or disable commands
Short options:-C For example:-L,-H
Long options:--word For example:--all,--human-readable
Parameters: Command object: such as file name and function name

Attention

1.  *多个选项以及多参数和命令之间使用空白字符串分隔*2. *取消和执行命令执行:Ctrl+c,Ctrl+d*3. *多个命令可以用 ; 符号分开*4. *一个命令可以用 \ 分成多行*
Command prompt with UID of user

Users in Linux, like Windows, are divided into administrators and ordinary users.
In Linux, the system is based on your UID to determine whether you are an administrator, rather than through your user name to determine

Linux Users

The system is based on the UID to determine whether the user is the root user, the root user uid is 0

Root user (super user)???
The root user is represented at the command prompt as # uid 0

A normal user command prompt is represented as $
Common user uid:?
CENTOS6: Starting from 500

Centos7: Starting from 1000

The color of the above prompt is based on the PS1 environment variable
>ps1=[\e[1;32m][\[email protected]\h \w]\$[\e[0m]

Bash Shell
Interactive interface
交互式接口:启动终端后,在终端设备附加一个交互式应用程序GUI:Graphic User InterfaceX protocol, window manager, desktopDesktop:GNOME (C, 图形库gtk),KDE (C++,图形库qt)XFCE (轻量级桌面CLI:Command Line Interfaceshell程序:sh(bourn 史蒂夫·伯恩)cshtcshksh(korn)bash (bourn again shell)GPL zsh

The Shell is the user interface of the Linux system and provides an interface for users to interact with the kernel. It receives the command entered by the user and feeds it into the kernel to execute.

For historical reasons, there are many shells. The shell is also known as the Linux command interpreter, which is responsible for translating different languages into the corresponding binary.
It's like different countries have different languages.
The shell is an interface between the user and the kernel, the operating system
The application accesses the system hardware and the kernel through system calls and libraries, and therefore Linux boot runs are loaded into memory. Reads faster than external commands.
The shell parses your commands into binary systems that the system can recognize to execute.

Bash Shel
GNU Bourne-again Shell (bash) is one of the most important tool software in the GNU program
Currently also a Linux standard shell, compatible with SH
CentOS Default Usage

Display the currently used shell
Echo ${shell}
Displays all shells used by the current system
Cat/etc/shells

Internal command

internal Commands are part of an integrated shell program that is identified by the shell program and runs inside the shell, typically loaded and hosted in system memory when the Linux system is loaded and run.

internal command help usage help cmd

View commands for internal commands
Enable: Disabling and enabling of internal commands
Help : to see if internal commands are disabled, the command is preceded with * Is the command that was disabled

External command

The external command simply says that the program runs on top of the system, and when the system reads the external command, it reads to the disk, which can be quite slow. Due to the characteristics of Linux, when the system looks for external commands, PATH环境变量 The system will follow the path from left to right one to find, when the previous path is found, the following path is not found.

~]# Echo $PATH

Help for external commands

Help Usagecmd --help

View Commands
which: view external commands in PATH the placed path, do not view the cache ( *PATH* shown in order of precedence)
Plus -A will look at all the PATH paths and command aliases in the external command
> Whereis: Find the path to the command and the path of the man help related documents

Determine if the command is an external command

Type:type cmd
The type cmd========= distinguishes between an external command or an internal command. is displayed according to the priority of the command.
The external command is the path (in the presence of an alias) in path, which is displayed according to the priority of the search command. But it will also be searched by the hash cache.)

Hash

The system initial hash table is empty, when the external command executes, the default is to look for the command from the path path, the path to the command is logged to the time hash table, when the command is used again, the shell interpreter will first look at the hash table, the existence will be executed, if not exist, will be looking under path. Using the hash cache table can greatly increase the call rate of the command.

Note: When we execute an external command, the hash table records the cache of the external command. But internal commands are not logged (internal commands are integrated into the Bash Shell ).
If you move this command to another path or path in the path variable at this point. To execute this command again, the command will error because the path is recorded in the hash table. Once the system has found the path, it will not look behind.

When Linux finds a command, does it look at the name of the command

When looking for a command, Linux finds it by its name, not by the nature of the command.

Command aliases

common commands for command aliases: Unalias Alias

When the system starts running, the alias configuration file (~/.BASHRC or/ETC/.BASHRC) on the disk is loaded into memory, and the system is running an in-memory alias . Even if you use Unalias to delete the alias, it is only in the current terminal can not perform aliases, and so on, and so on the system to log back on, you can use this alias. Because there is no alias configuration file Ah!

How command aliases use the original command
    • In front of the command add \

    • Write on full path, (internal command not applicable)

    • Enclose the command in single quotation marks.
Search paths for commands in Linux

When you hit a string at the command prompt, in the background do one thing, first use/bin/bash this program, to determine what you enter the content is the program, is not able to find this program. First determine whether the command alias, and then determine whether it is an internal key command, and then see if there is an external command cache hash, and finally determine whether the foreign key command pash. and then error.

The command mechanism of 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.