23. Shell Introduction, Command history, command completion and aliases, wildcard characters, input and output redirection

Source: Internet
Author: User
Tags aliases

23. Shell Introduction, Command history, command completion and aliases, wildcard characters, input and output redirection

First, Shell introduction

The shell is the intermediate medium that the system interacts with the computer hardware, it is just a tool of the system. There is a layer of stuff between the shell and the computer hardware-the system kernel. If the computer hardware compared to the human body, the system kernel is the brain, Shell is the facial features. The user directly faces not the computer hardware but the shell, the user instructs the shell, then the shell again to the system kernel, and then the kernel to control the computer hardware to perform various operations.

The shell is a command interpreter that provides interaction between the user and the machine.

Each user can have their own specific shell.

Centos7 default shell for bash (Bourne Agin Shell)

The system also has zsh, ksh shell, there are differences in detail.

The shell also has its own specific syntax, such as logical judgments, loops.

Ii. History of the Order

History Command View command

The path where the/root/.bash_history

You can use this command to see how many bars are saved, with a maximum of 1000 files.

The command is configured by an environment variable: histsize. The echo $HISTSIZE can be viewed as 1000, representing the maximum number of 1000 commands, which is the system built-in environment variable. Out of the 1000th after the command, not deposited in the command history, temporarily exist in memory.

# history-c Empty the command history in memory, can't empty the config file

Only when exiting the current terminal, the command will be stored in the configuration file, in the terminal when there is memory in the command history.

Define the configuration file for the environment variable histsize:/etc/profile

You can find the histsize directly after entering, and you can change the data to the amount you want to define.

After the change is saved, the # source/etc/profile command must be executed, otherwise the variable will not take effect, or it can be re-entered into the terminal.

# histtimeformat= "%y/%m/%d%h:%m:%s" The mission gives history time to show. Valid only at the current terminal. Y: Year; m: month; d: date; h: Hours; M: minutes; S: seconds.

To make it permanent, write it to the configuration file/etc/profile, and put it in the line below histsize=1000. After writing to the configuration file, save and exit, and then re-enter the terminal to verify that the command history has time to display.

# chattr +a ~/.bash_history

Permanent save, so that the command history of the configuration file directly append cannot be deleted. If you do not exit normally, the command will not be saved to the command history.

# !! The last command in the command history.

#!n n followed by numbers, you can execute the nth command in the command history again.

#!echo from the back and forth in the command history, look for commands that begin with ECHO, such as!tree, and so on.

Iii. command Completion and aliases

The command complements the TAB key, taps the completion, and taps twice to search out more than 2 options starting with the command. You can complete the command and file path.

Command parameter completion: CENTOS7 support, requires # yum install-y bash-completion. Install this package. CENTOS6 only supports the completion of the command itself, and it will need to restart the system after installation.

Command parameters such as Systemctl restart Network.service.

# alias restartnet= "Systemctl Restart Network.service"

Make an alias for this long command. When you use it, you can hit the alias.

Unalias de-alias.

Alias location: Under BASHRC and/etc/profile.d/under the user's home directory. The custom alias is under. bashrc.

Four, wildcard characters

* Indicates a wildcard, no character, no number of points

? Represents a match for a character, such as LS?. TXT, it will list all the files in. txt.

[] Example: LS [0-3].txt or LS [123456].txt. Write a range.

{} and [] similar, but this {} to add a comma, such as {1,2,3,4}

V. Input/Output redirection

> Output redirection

> Input the output of the preceding command into the following file. A greater-than sign will remove the back file and overwrite the previous output with the following file. So generally with two >>, append the meaning, will not delete the original file.

2>, the command generates the error message specified by the input to a file. 2>>, error message append redirect.

>+2>=&>, output the correct and incorrect information to a later file. You can use &> to express.

< Enter the reverse usage of the redirect,>. The left must be a command and cannot be a file reverse input to a file.


23, Shell Introduction, command history, 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.