Shell introduction, history commands, command completion and aliases, wildcard characters, input and output redirection

Source: Internet
Author: User
Tags aliases

Shell Introduction

The shell is the intermediate medium used when the system interacts with the computer hardware, and it is just a tool of the system. There is a layer of things between computer hardware-the system kernel. If computer hardware is likened to a human body, the kernel of the system is the human brain. As for the shell, it seems more appropriate to compare it to the facial features of the human being. The user is not directly facing the computer hardware but the shell, the user tells the shell, and then the shell to the system kernel, and then the kernel to control the computer hardware to perform various operations.


Red Hat/centos the shell version installed by default is bash (Bourne Again shell), which is an enhanced version of SH (Bourne shell). The Bourne shell was one of the first shell versions to pop up. The founder was Steven Bourne, who was named the Bourne Shell to commemorate him, referred to as SH.




Command history

The commands we have executed Linux are recorded and are expected to record 1000 historical commands. These commands are saved in the. bash_history file in the user's home directory. However, it is important to note that commands that run in the current shell are saved to the. bash_history file only if the user exits the current shell normally.


[Email protected] ~]# history

650) this.width=650; "Src=" Https://s2.51cto.com/oss/201711/15/0eebd83bb2c9d66074be16b227ee1daf.png-wh_500x0-wm_3 -wmp_4-s_941361731.png "title=" 1.png "alt=" 0eebd83bb2c9d66074be16b227ee1daf.png-wh_ "/>


Echo $HISTSIZE See how many history commands are currently saved

History-c empties the history command in memory. and the historical order in the./root/.bash_history is still there.

650) this.width=650; "Src=" Https://s5.51cto.com/oss/201711/15/5d833d614f54c261c9585c07c20b151b.png-wh_500x0-wm_3 -wmp_4-s_330307797.png "title=" 2.png "alt=" 5d833d614f54c261c9585c07c20b151b.png-wh_ "/>


You can change the number of historical command bars by changing the value of Histsize in Vi/etc/profile.

650) this.width=650; "Src=" Https://s2.51cto.com/oss/201711/15/b6152ab95dd0b86d8bb43a0003a426af.png-wh_500x0-wm_3 -wmp_4-s_671839128.png "title=" 3.png "alt=" B6152ab95dd0b86d8bb43a0003a426af.png-wh_ "/>


You need to restart or execute source/etc/profile to take effect, then view becomes 5000.

650) this.width=650; "Src=" Https://s1.51cto.com/oss/201711/15/94fd70476962f54a733f05f750541005.png-wh_500x0-wm_3 -wmp_4-s_3791734745.png "title=" 4.png "alt=" 94fd70476962f54a733f05f750541005.png-wh_ "/>


Log command Run time

Execute histtimeformat= "%y/%m/%d%h:%m:%s"

650) this.width=650; "Src=" Https://s4.51cto.com/oss/201711/15/20342229598584b98d34ef477b048a6d.png-wh_500x0-wm_3 -wmp_4-s_3683464423.png "title=" 5.png "alt=" 20342229598584b98d34ef477b048a6d.png-wh_ "/>

Now you can see the time the command was executed.


but only temporarily, if you change a terminal or restart the terminal after the failure, to be permanently effective, you need to add the histtimeformat= "%y/%m/%d%h:%m:%s" command to the/etc/profile file.

650) this.width=650; "Src=" Https://s3.51cto.com/oss/201711/15/61d15971f7ae46e83a21463decd18115.png-wh_500x0-wm_3 -wmp_4-s_2577221622.png "title=" 6.png "alt=" 61d15971f7ae46e83a21463decd18115.png-wh_ "/>


Permanently save the input command history

Add hidden permissions to the file a (append only, cannot delete the modification.) )

Chattr +a/root/.bash_history


Special characters related to the command history:

!! : Two in a row! Represents the execution of the previous command.

650) this.width=650; "Src=" Https://s2.51cto.com/oss/201711/15/beed0f5694d71dde16ff945106c7013e.png-wh_500x0-wm_3 -wmp_4-s_3231017701.png "title=" 7.png "alt=" Beed0f5694d71dde16ff945106c7013e.png-wh_ "/>


! N: = # represents a number that represents the nth command in the execution history of a command. For example! 15

650) this.width=650; "Src=" Https://s5.51cto.com/oss/201711/15/a2385658c85c90c249134ee309d57188.png-wh_500x0-wm_3 -wmp_4-s_162470269.png "title=" 8.png "alt=" A2385658c85c90c249134ee309d57188.png-wh_ "/>


! String: for example! The CD represents the last command in the command history that starts with a CD

650) this.width=650; "Src=" Https://s4.51cto.com/oss/201711/15/a8ad3ca29ebb63b9b3f7b556d1c6584d.png-wh_500x0-wm_3 -wmp_4-s_2876164006.png "title=" 9.png "alt=" A8ad3ca29ebb63b9b3f7b556d1c6584d.png-wh_ "/>


Command completion

Pressing the TAB key will help us complete an instruction, a path, or a file name. Press the TAB key two times, and the system will list all the commands or filenames. Only command completion is currently supported, and parameters are not supported for completion.

650) this.width=650; "Src=" Https://s2.51cto.com/oss/201711/15/6c74d4a621ccfd7b8e0f4a1747b01912.png-wh_500x0-wm_3 -wmp_4-s_721511000.png "title=" 10.png "alt=" 6c74d4a621ccfd7b8e0f4a1747b01912.png-wh_ "/>





Alias

Use alias to name a common and long command as a simple and easy-to-remember instruction. Enter alias to see which commands are using aliases.

650) this.width=650; "Src=" Https://s5.51cto.com/oss/201711/15/850d0225b0eb11c0cbdef2f0a98e019b.png-wh_500x0-wm_3 -wmp_4-s_3159976112.png "title=" 11.png "alt=" 850d0225b0eb11c0cbdef2f0a98e019b.png-wh_ "/>


Alias command alias = ' specific command ' aliases for custom commands

650) this.width=650; "Src=" Https://s4.51cto.com/oss/201711/15/49c71adffb04fe76e66efad82cd4ee38.png-wh_500x0-wm_3 -wmp_4-s_485763764.png "title=" 12.png "alt=" 49c71adffb04fe76e66efad82cd4ee38.png-wh_ "/>


Unalias can de-alias function

650) this.width=650; "Src=" Https://s2.51cto.com/oss/201711/15/d5f5605482be4b33c53ea9cca6d61947.png-wh_500x0-wm_3 -wmp_4-s_3834253979.png "title=" 13.png "alt=" D5f5605482be4b33c53ea9cca6d61947.png-wh_ "/>





Wildcard characters

Under Bash, you can use * to match 0 or more characters, with a. Matches one character.

650) this.width=650; "src=" Https://s3.51cto.com/oss/201711/15/e62b10e85aa07d3f147c3ed5cfcfcf3e.png "title=" Clipboard (8). png "alt=" E62b10e85aa07d3f147c3ed5cfcfcf3e.png "width=" 650 "style=" padding:0px;margin:0px; Vertical-align:top;border:none; "/>







Input and output redirection

Input redirection is used to change the input of the command, and output redirection is used to change the output of the command. Output redirection is more common, and it is often used for command results to be entered into a file instead of on-screen. Enter the redirected command <, and the output redirection command is >. In addition, there are error redirect command 2> and append redirect command >>

650) this.width=650; "Src=" Https://s2.51cto.com/oss/201711/15/c4490106280eab756e4199377dbb6fea.png-wh_500x0-wm_3 -wmp_4-s_1137634644.png "title=" 14.png "alt=" C4490106280eab756e4199377dbb6fea.png-wh_ "/>


650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0035.gif "alt=" J_0035.gif "/>

This article is from the "Operation and maintenance of the Road" blog, please be sure to keep this source http://ccj168.blog.51cto.com/13163491/1982134

Shell introduction, history commands, command completion and aliases, wildcard characters, input and output redirection

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.