Shell Introduction, Command History, command and file name auto-complete; wildcard and input \ Output redirection

Source: Internet
Author: User

Shell Introduction

The shell is the user interface of the system and provides an interface for users to interoperate with the kernel. It receives the command entered by the user and feeds it into the kernel to execute.
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.
Bash (GNU bourne-again shell) is the default shell for many Linux distributions. In fact, there are a lot of traditional Unix shells, such as tcsh, CSH, Ash, BSH, Ksh, and so on, shell script is roughly the same, when you learn a shell, the other shells will soon get started, most of the time, a shell Script can usually be used on many kinds of shells.

1. Record History Order

The commands we've knocked on, Linux will be recorded, and presets can record 1000 historical commands. These commands are saved in the. bash_history file in the user's home directory. One thing you need to know is that commands that run in the current shell are saved to the. bash_history file only when the user exits the current shell normally.

# history              //查看命令历史记录

# cat ~/.bash_history             //命令历保存在这个文件

# echo $HISTSIZE           //查看当前系统可以保存多少条命令历史# vim /etc/profile       //修改HISTSIZE参数# source /etc/profile         //使修改过的参数生效,否则无效


HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S"            //设置参数显示命令执行时间


However, this will only temporarily show the time after the restart, and if you need to display it permanently, you need to add the parameter to the configuration file.

# vi /etc/profile    //加入HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S"参数# source /etc/profile   //是加入参数后的文件生效

chattr +a /root/.bash_history  //加上隐藏权限a,使这个文件只能追加,无法删除修改,以永久保存命令历史记录

A special character associated with the history command '! ', three commonly used:

!! : Two in a row! Represents the execution of the previous command.
! String: For example, the last command that starts with a CD in the !cd execution command history
!n:n represents a number that represents the nth command in the execution history of a command.

2. Automatic completion of commands and documents

This feature was introduced at the beginning Amin, remember? It just presses the TAB key, which can help you complete a command, or help you to complete a path or a file name. Press the TAB key two times consecutively, and the system will list all the instructions or filenames.
If parameters are required, you will need to install the RPM package

# yum install -y bash-completion# reboot    //重启系统生效

After the installation, we can test the parameters that begin with the RE:

3. Wildcard characters

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

4. Input/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 <
The command to output redirects is;
Error redirection command 2>
Append redirect Command >>.

Instance:
1. Output redirection (overwrite original) and append redirect:

2. Error redirection:

3. Simultaneous redirection of outputs and errors:

3. Input redirection:

Shell Introduction, Command History, command and file name auto-complete; wildcard and input \ 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.