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

Source: Internet
Author: User
Tags aliases

Shell Introduction
    • The shell is a command interpreter that provides interaction between the user and the machine
    • Supports specific syntax, such as logical judgment, looping
    • Each user can have their own specific shell
    • CentOS7 default shell is bash (Bourne Agin Shell)
    • and Zsh,ksh and so on.
Command history
    • Maximum Deposit 1000.
    • Variable Histsize modified in/etc/profile
      vi /etc/profile找到HOSTNAME=`/usr/bin/hostname 2>/dev/null`HISTSIZE=1000if [ "$HISTCONTROL" = "ignorespace" ] ; then如果觉得1000条不够可以改成5000

After the change, you must exit the terminal to re-enter or source/etc/profile change

    • Variable Value re-assignment

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

[[email protected] ~]# history     1  ls    2  ls /etc/passwd    3  cat /etc/passwd    4  [[email protected] ~]# cat /etc/passwd    5  root:x:0:0:root:/root:/bin/bash    6  bin:x:1:1:bin:/bin:/sbin/nologin    7  daemon:x:2:2:daemon:/sbin:/sbin/nologin    8  adm:x:3:4:adm:/var/adm:/sbin/nologin    9  lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin

After the value is re-assigned

[[email protected] ~]# HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S "[[email protected] ~]# history     1  2017/08/30 19:20:18 ls    2  2017/08/30 19:20:18 ls /etc/passwd    3  2017/08/30 19:20:18 cat /etc/passwd    4  2017/08/30 19:20:18 [[email protected] ~]# cat /etc/passwd    5  2017/08/30 19:20:18 root:x:0:0:root:/root:/bin/bash    6  2017/08/30 19:20:18 bin:x:1:1:bin:/bin:/sbin/nologin    7  2017/08/30 19:20:18 daemon:x:2:2:daemon:/sbin:/sbin/nologin    8  2017/08/30 19:20:18 adm:x:3:4:adm:/var/adm:/sbin/nologin

Then open a new terminal, this environment variable is not in effect.

If you want this environment variable to take effect globally, you need to edit/etc/profile to add histtimeformat= "%y/%m/%d%h:%m:%s" to the inside

fiHOSTNAME=`/usr/bin/hostname 2>/dev/null`HISTSIZE=5000HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S"if [ "$HISTCONTROL" = "ignorespace" ] ; then    export HISTCONTROL=ignoreboth

Effective after Source/etc/profile

    • Permanently save command history

      Chattr +a ~/.bash_history

Can only append cannot delete

    • If you do not exit normally, the history command is not fully saved
    • !!

      Represents running the last history command

    • !n

      Specify the number of Run history rows command

    • ! command

      Represents the last command in command history to enter this command

Command completion and aliases
    • tab, knock, Knock, double click.
    • CENTOS7 support parameter completion, the default is not, you need to install Yum install-y bash-completion after restarting the system to take effect.
    • Alias aliases, give the command a new name

Alias exists in the. bashrc file in the user's home directory.

There are still some/etc/profile.d/below

Unalias to cancel a custom alias

Wildcard characters *
[[email protected] ~]# ls111  1eer  1.txt  2.txt  anaconda-ks.cfg  erwe[[email protected] ~]# ls *.txt1.txt  2.txt[[email protected] ~]# [[email protected] ~]# ls 1*1eer  1.txt111:[[email protected] ~]# ls *1*1eer  
?

Question mark denotes any one character

[[email protected] ~]# ls ?.txt1.txt  2.txt[[email protected] ~]# ls *.txt1.txt  2.txt  bbcc.txt  
[]

Select Range

[[email protected] ~]# ls [123].txt1.txt  2.txt[[email protected] ~]# ls [0-9].txt1.txt  
{}

It's also a choice, similar to [], but with a comma in the middle.

[[email protected] ~]# ls {1,2}.txt1.txt  
Input/Output redirection >

Remove the content from the > front to redirect to the back content.

>>

Append the contents of the >> front to the following content.

2>

Indicates that the information for the run error is directed to a file

[[email protected] ~]# fddd-bash: fddd: 未找到命令[[email protected] ~]# fddd 2> 1.txt [[email protected] ~]# cat 1.txt -bash: fddd: 未找到命令
2>>

Error Append redirect

&>

Error and correct output redirection

<

Input redirect

Enter the contents of the < right side of the file into the < left command.

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.