Shell, internal and external commands--linux basic commands (2)

Source: Internet
Author: User

1.Shell

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 .

The shell is also known as the LINUX command interpreter (commandinterpreter).

Vshell is a high-level programming language .

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/9D/13/wKiom1l5qNOixe4FAAI_C5XLLcQ312.png "style=" float : none; "title=" Image001.png "alt=" Wkiom1l5qnoixe4faai_c5xllcq312.png "/>

2.bash Shell

Gnubourne-againshell (bash) is one of the most important tool software in the GNU program and is currently the Linux standard Shell, compatible with SH .

(1) to query which of the current system usesShell

Use Echo$shell

the function of ECHO is to output what, so,echo A variable value is to refer to the variable, you can display the current system Shell as bash.

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/9D/13/wKioL1l5qNSxDO3jAAB1oUWS1yE597.png "title=" Image002.png "style=" Float:none; "alt=" Wkiol1l5qnsxdo3jaab1ouws1ye597.png "/>


PS: Be sure to enter $, no then the system will not recognize that it is a variable, just as a string display.

(2) to query the current system for all installedShell

Use cat/etc/shells

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/9D/13/wKiom1l5qNSTY_uEAABZYuaiM34322.png "title=" Image003.png "style=" Float:none; "alt=" Wkiom1l5qnsty_ueaabzyuaim34322.png "/>


3.Shellprompt(1) prompt Format

Bash 's original format is:

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/9D/13/wKiom1l5qU6QBqPVAAAKWViZF_U771.png "style=" float : none; "title=" Image004.png "alt=" Wkiom1l5qu6qbqpvaaakwvizf_u771.png "/>

Display name and version number.

However, the prompt format is not very useful, so centos6 changes the default value of the prompt to the following format:

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M02/9D/13/wKioL1l5qU7BcUv7AAAXQCbhljs482.png "title=" Image005.png "style=" Float:none; "alt=" Wkiol1l5qu7bcuv7aaaxqcbhljs482.png "/>

This format can visually display the current user name root and hostname centos6 and directory ~ and user type #.

(2) query host name

the command to query the host name is hostname

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/9D/13/wKioL1l5qU7DSp-1AAAKx7IPdaU742.png "title=" Image006.png "style=" Float:none; "alt=" Wkiol1l5qu7dsp-1aaakx7ipdau742.png "/>

It can be found that the host name displayed at the prompt is not the full hostname, but only the first part of the display, in order to facilitate the distinction.

(3) directory Display

~ indicates the current directory. If not entered, the default is ~.

When entering a directory, the last section of the path is displayed.

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M01/9D/13/wKiom1l5qYnxHYstAAB_6uY2moY870.png "style=" float : none; "title=" Image007.png "alt=" Wkiom1l5qynxhystaab_6uy2moy870.png "/>

It can be found that the path displayed by the prompt is not the full path, only the last part is displayed, in order to make sure that the user has actually entered this directory.

(4) to query the current directory

using Commands pwd

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M01/9D/13/wKioL1l5qYqBHryqAAAbyJoeq3w987.png "title=" Image008.png "style=" Float:none; "alt=" Wkiol1l5qyqbhryqaaabyjoeq3w987.png "/>

To display the current directory.

(5) User Type

# represents the root user, and$ represents a normal user.

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M02/9D/13/wKiom1l5qYqhrt_mAAAxes6bR60046.png "style=" float : none; "title=" Image009.png "alt=" Wkiom1l5qyqhrt_maaaxes6br60046.png "/>

(6) Modify the prompt

PS1 is a variable name that prompts for formatting, so you can use the Echo view prompt format

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M02/9D/13/wKioL1l5qYrx6ZIZAAAtOeRhqr8930.png "title=" Image010.png "style=" Float:none; "alt=" Wkiol1l5qyrx6zizaaatoerhqr8930.png "/>

You can see that the format is the prompt format.

Some of the prompt formats are as follows:

\u: Current User

\h: hostname short name

\h: Full host name

\w: Full working directory name, home directory will be replaced by ~

\w: Last directory

\ T: hourly time Format

\ T: hourly time Format

\! : number of command histories

\#: number of command history after boot

If you want to modify the format, you can PS1 re-assigns the value, using = assignment.

We change h to uppercase H,W to lowercase w, and note that you want to hit a space after $ to make the format beautiful.

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M01/9D/13/wKioL1l5qfGhdZyYAAAekejWHTo607.png "style=" float : none; "title=" Image011.png "alt=" Wkiol1l5qfghdzyyaaaekejwhto607.png "/>

We found that the hostname and user name were displayed as complete.

PS:$ Two should be entered in front of \, because $ itself is a special character,\$ can make it into ordinary characters.

(7) Permanently modify the prompt

we found that by simply using the above method,exit exits and then logs back to the original default state. Therefore, we have a way to make it permanently modified.

will be export ps1= "[\[email protected]\h \w]\$" command to the last line in the ~/.BASHRC file of the currently logged-on user , and then use the source ~/.bashrc# to make it effective.

(8) to modify the color

Use ps1= "\[\e[33m\][\[email protected]\h\w]\\$ \[\e[0m\]" Modify the prompt color

The color table is as follows:

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/9D/13/wKiom1l5qfHRS_SgAAAT60qrIUQ890.png "title=" Image012.png "style=" Float:none; "alt=" Wkiom1l5qfhrs_sgaaat60qriuq890.png "/>

, the modification succeeds:

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/9D/13/wKioL1l5qi7BZNxwAAAwgfzF2hw699.png "style=" float : none; "title=" Image013.png "alt=" Wkiol1l5qi7bznxwaaawgfzf2hw699.png "/>



4.internal commands and external commands

internal command: comes with a shell and is provided in a command form

Internal commands are transferred into memory when the system starts, and are resident in memory, so the execution efficiency is high.

External command: A corresponding executable program file under the file system path

External commands are software features of the system that are read into memory from the hard disk when required by the user.

5.Command Type(1) to determine the type of command

Use type you can tell if a command is an internal command or an external command .

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M00/9D/13/wKiom1l5qi_zoKYLAAATiNiyHyI477.png "style=" float : none; "title=" Image014.png "alt=" Wkiom1l5qi_zokylaaatiniyhyi477.png "/>

,the CD is an internal command, andthe Ifconfig is an external command.


(2)EnableShow all enabled internal commands

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/9D/13/wKioL1l5qi_imt2kAAAijQvm7h8324.png "style=" float : none; "title=" Image015.png "alt=" Wkiol1l5qi_imt2kaaaijqvm7h8324.png "/>


(3)Enable |wc-lCount the number of internal commands enabled (LIt's a letter, not a number1)

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M00/9D/13/wKioL1l5qi_xZh3ZAAAh7hvHGSs532.png "style=" float : none; "title=" Image016.png "alt=" Wkiol1l5qi_xzh3zaaah7hvhgss532.png "/>

statistics out the total of the article


(4)enable-n COMMANDDisable Command

If you enter enable–n BG, you can disable bg.

input enable |wc–l query found only a few

again with the Enable query, found that there is no BG, that is disabled.

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M01/9D/13/wKioL1l5qr6SYQfKAAAr6ezyoPQ105.png "style=" float : none; "title=" Image017.png "alt=" Wkiol1l5qr6syqfkaaar6ezyopq105.png "/>

input Enable–n can query all commands that are disabled

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M01/9D/13/wKiom1l5qr-RQa5tAAAQ6oqn62A553.png "style=" float : none; "title=" Image018.png "alt=" Wkiom1l5qr-rqa5taaaq6oqn62a553.png "/>

Similarly, you can use enable-n |wc-l Count the number of internal commands that are disabled


(5)Enable COMMANDStart Command

use enable to restart a disabled command

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M02/9D/13/wKiom1l5qr-TFG-oAAAWZ8W2Pro205.png "style=" float : none; "title=" Image019.png "alt=" Wkiom1l5qr-tfg-oaaawz8w2pro205.png "/>

The three commands are restarted, the query is disabled and the number of startup commands is restored to a full scale .

(6) about disabling

Disabling internal commands does not mean that you cannot use them, but rather that you need to find the corresponding external commands from the hard disk.

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M02/9D/13/wKioL1l5qsDDqqmOAAC7bq9-2cM215.png "style=" float : none; "title=" Image020.png "alt=" Wkiol1l5qsddqqmoaac7bq9-2cm215.png "/>


6. Hash(1) Cache Path

The system initial hash table is empty, when the external command executes, the default is to look for the command from the path path, and when it is found, the path to the command is recorded in the hash table, and when the command is used again, The shell interpreter first looks at the hash table, where it will be executed, and if it does not exist, it will go to the variable path path.

use echo to view path paths:

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/9D/13/wKiom1l5qsCyOCNRAABqfpy9ubw762.png "style=" float : none; "title=" Image021.png "alt=" Wkiom1l5qscyocnraabqfpy9ubw762.png "/>

Look for the colon as a spacer, from left to right.

using the hash cache table can greatly increase the call rate of the command.

,fdisk is an external command that, when run, has a hash of the command that willcache the path.

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M01/9D/13/wKiom1l5qziRSsx2AAKbVJun0ik185.png "style=" float : none; "title=" Image022.png "alt=" Wkiom1l5qzirssx2aakbvjun0ik185.png "/>

you don't have to go after the cache. path is searched in turn.

Here's an example. Run pwd ifconfig path in Pwd command, will Ifconfig copy to Pwd before the path and also named Pwd/usr/local/sbin/pwd ifconfig< Span style= "font-family: ' The song Body '; The content, but we do pwd pwd pwd/bin/pwd

This means that the PWD path has been cached to /bin/pwd in the previous run, so it is not necessary to look in the path path again, but to call the hash The path in the cache.

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M01/9D/13/wKiom1l5qznQxjH8AABnW5JdRoY434.png "style=" float : none; "title=" Image023.png "alt=" Wkiom1l5qznqxjh8aabnw5jdroy434.png "/>


(2)Hashdisplay is currentlyHashall external commands for

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M01/9D/14/wKioL1l5qzqT86qvAACnDJz8kCE686.png "style=" float : none; "title=" Image024.png "alt=" Wkiol1l5qzqt86qvaacndjz8kce686.png "/>


hash-l Displays the external command currently being hashed , including the alias

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M02/9D/13/wKiom1l5qzqB2Ck-AAE02UCH_4U103.png "style=" float : none; "title=" Image025.png "alt=" Wkiom1l5qzqb2ck-aae02uch_4u103.png "/>


(3)hash-d nameDeleteHash

Now we will delete the cached pwd in the hash , and the name we need to enter when we delete It is the alias we found with hash-l .

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M01/9D/14/wKioL1l5qzuBYp6QAAC5QHVv0zU321.png "style=" float : none; "title=" Image026.png "alt=" Wkiol1l5qzubyp6qaac5qhvv0zu321.png "/>

you can see that the PWD is not in the list .

then we look at the type of PWD and find that the address has been copied to the previous address because the cache has been deleted.

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M02/9D/14/wKiom1l5qzuwlFilAAA33yLP1-g651.png "style=" float : none; "title=" Image027.png "alt=" Wkiom1l5qzuwlfilaaa33ylp1-g651.png "/>

Therefore, the implementation of the PWD at this time should be ifconfig content.

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/9D/14/wKioL1l5qz2gi877AAQdTyv-ChQ893.png "style=" float : none; "title=" Image028.png "alt=" Wkiol1l5qz2gi877aaqdtyv-chq893.png "/>

PS: You can also use hash-r to Clear all the hashes.

hash-p/.../.... Name can be manually add a hash cache.

Summary: when a command is executed, it has the following precedence: internal command > hash> PATH


This article is from the "ty_endless" blog, make sure to keep this source http://tyendless.blog.51cto.com/12435756/1951492

Shell, internal and external commands--linux basic commands (2)

Related Article

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.