20.Shell Introduction, History,tab key, wildcard, redirect

Source: Internet
Author: User
Tags aliases egrep

Five Week third session (January 10)

8.1 Shell Introduction

8.2 Command History

8.3 Command Completion and aliases

8.4 Wildcard Characters

8.5 Input and output redirection

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
    • History command
[[email protected] ~]# history    1  vi /etc/sysconfig/network-scripts/ifcfg-ens33    2  systemctl restart network.service    3  ip addr    4  ping -c 4 www.baidu.com    5  yum groupinstall -y "GNOME Desktop"    6  init5    7  init 5    8  vi /root/.ssh/authorized_keys    9  setenforce 0   10  vi /etc/selinux/config   11  mkdir /root/.ssh
    • . bash_history Maximum 1000 strips
      [[email protected] ~]# echo $HISTSIZE1000  //运行的命令只能保存1000条
    • History-c, in-memory command emptying
      [[email protected] ~]# history -c[[email protected] ~]# history1  history
    • Cat. Bash_history View history configuration file, not emptied
[[email protected] ~]# cat .bash_historyvi /etc/sysconfig/network-scripts/ifcfg-ens33systemctl restart network.serviceip addrping -c 4 www.baidu.comyum groupinstall -y "GNOME Desktop"init5init 5vi /root/.ssh/authorized_keyssetenforce 0vi /etc/selinux/configmkdir /root/.sshchmod 700 /root/.sshvi /root/.ssh/authorized_keysssh -vyum install -y openssh-clientyum install -y openssh-clientsinit 5init 6
    • Variable histsize
      /etc/profile modified, modify complete with the source command to complete the update


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

[[email protected] ~]# echo $HISTSIZE1000[[email protected] ~]# source /etc/profile[[email protected] ~]# echo $HISTSIZE5000
    • Change the definition of the environment variable Histimeformat to change the format of the history
      [[email protected] ~]# HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S "[[email protected] ~]# echo $HISTTIMEFORMAT%Y/%m/%d %H:%M:%S[[email protected] ~]# history1  2018/01/10 23:18:28 history2  2018/01/10 23:20:12 cat bash_history3  2018/01/10 23:20:38 cat .bash_history4  2018/01/10 23:25:45 ls -l .bash_history5  2018/01/10 23:25:49 ls6  2018/01/10 23:26:44 vi /etc/profile7  2018/01/10 23:32:44 echo $HISTSIZE8  2018/01/10 23:33:02 source /etc/profile9  2018/01/10 23:33:05 echo $HISTSIZE

      After creating a new SSH channel, it is no longer useful, in order to completely change, need to re-edit/etc/profile

[[email protected] ~]# vim /etc/profile[[email protected] ~]# source !$source /etc/profile

    • Permanently save chattr +a ~/.bash_history
    • Abnormal shutdown exit, command save incomplete

    • !! Represents the execution of the previous command
    • !n represents the first instruction in the history of the execution of a command
    • !word represents the most recent command in command history that begins with Word

      Command completion and aliases
    • Tab key, tap, fill instruction
      Two knocks, and the system will list all the command files.

    • Parameter completion, installation Bash-completion
[[email protected] ~]# yum install -y bash-completion
    • When the command is not clear, the command is not complete with the TAB key
[[email protected] ~]# systemctl resrescue        reset-failed  restart       [[email protected] ~]# systemctl restart networknetwork-online.target  network.service        [[email protected] ~]# systemctl restart network.service
    • Alias aliases give the command a name again
[[email protected] ~]# alias restartnet=‘systemctl restart network.service‘[[email protected] ~]# restartnet
    • What are the alias commands

      [[email protected] ~]# aliasalias cp=‘cp -i‘alias egrep=‘egrep --color=auto‘alias fgrep=‘fgrep --color=auto‘alias grep=‘grep --color=auto‘alias l.=‘ls -d .* --color=auto‘alias ll=‘ls -l --color=auto‘alias ls=‘ls --color=auto‘alias mv=‘mv -i‘alias restartnet=‘systemctl restart network.service‘alias rm=‘rm -i‘alias which=‘alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde‘
      • Each user has their own configuration alias file ~/.BASHRC

    • ls/etc/profile.d/
      Custom alias put to ~/.BASHRC

    • Unalias Canceling aliases
[[email protected] profile.d]# unalias restartnet[[email protected] profile.d]# restartnetbash: restartnet: 未找到命令...
Wildcard, input and output redirection
    • [] ls. txt//used to match 0 or more characters
    • [] ls?. TXT//use? Match one character
    • [] LS [0-9].txt; ls [12].txt//Range & or
    • [] ls {1,2}.txt//
    • [] Cat 1.txt >2.txt//The results of the previous command are directed to the following document, the original document is deleted
    • [] Cat 1.txt >> 2.txt//Append, original document not deleted
    • [] LS aaa.txt 2>err
[[email protected] profile.d]# lsaabash: lsaa: 未找到命令...[[email protected] profile.d]# lsaa 2>a.txt[[email protected] profile.d]# cat a.txtbash: lsaa: 未找到命令...
    • [] LS aaa.txt 2>>err
    • [] Wc-l < 1.txt
    • [] Command >1.txt 2>&1

20.Shell Introduction, History,tab key, wildcard, redirect

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.