Shell introduction, History, aliases, wildcards and redirects

Source: Internet
Author: User
Tags aliases egrep

Shell Introduction
    • The shell is a command interpreter that provides interaction between the user and the machine
    • Support for specific grammars, such as logical judgments, loops
    • Each user can have their own specific shell
    • CentOS7 default shell for Bash, (Bourne Agin Shell commemorates Bourne named)
    • and Zsh,ksh and so on.
Historical command
  • History Command---View historical commands
  • . Bash_history---command history save the file in the user's home directory, when exiting the terminal
    [[email protected] ~]# ls /root/.bash_history /root/.bash_history
  • Maximum Storage 1000
  • History-c clears the command history, just empties the memory, does not delete the file,
    [[email protected] ~]# history -c[[email protected] ~]# history2  history
  • Defined by the variable histsize
    [[email protected] ~]# echo $HISTSIZE1000
  • Variables can be modified in/etc/profile to increase the number of decreases
    [[email protected] ~]# vim /etc/profileHOSTNAME=`/usr/bin/hostname 2>/dev/null`HISTSIZE=5000[[email protected] ~]# source /etc/profile[[email protected] ~]# echo $HISTSIZE5000改完需要source才能生效
  • histtimeformat= "%y/%m/%d%h:%m:%s"---Add this variable to show the usage time of the history command
    • Permanent entry, Edit file
      [[email protected] ~]# vim /etc/profileHISTSIZE=5000HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S"[[email protected] ~]# source /etc/profile
  • Command history saved permanently: Chattr +a ~/.bash_history
    ---Give a permission, can only append cannot delete, if does not exit the terminal correctly, the record command is not complete
  • !! ---the last command in the execution history
  • !755---Perform 755 commands in history
  • !mkdir---Execute the command starting at the bottom of the first mkdir
Command completion and aliases
  • tab, tap (fill the unique) knock twice (show all that starts with it)
  • CENTOS7 Support Command parameter completion, need to install Yum install-y bash-completion, and restart the system
  • Alias can set aliases for commands
    [[email protected] ~]# alias restartnet=‘systemctl restart network.service‘[[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‘
  • Unalias alias---The alias of the cancellation command
  • Each user has their own configuration alias file ~/.BASHRC, in the user's home directory
  • ls/etc/profile.d/----There are some in this directory
    [[email protected] ~]# ls /etc/profile.d/256term.csh         colorgrep.csh  colorls.sh  less.csh  vim.sh256term.sh          colorgrep.sh   lang.csh    less.sh   which2.cshbash_completion.sh  colorls.csh    lang.sh     vim.csh   which2.sh
Wildcard characters
    • ls . txt--- can represent any character and string
        [[email protected] ~]# ls *.txt1.txt 2.txt 3.txt a.txt bb.txt [[email protected] ~]# ls *txt1.txt 2.txt 3.txt a.txt bb.txt[[email protected] ~]# ls *txt*1.txt 2.txt 3.t XT a.txt Bb.txt  
    • ls?. TXT----? Can only represent one character
        [[email protected] ~]# ls?. Txt1.txt 2.txt 3.txt a.txt[[email protected] ~]# ls1.txt 2.txt 3.txt anaconda-ks.cfg a.txt bb.txt[[email  ;p rotected] ~]# ls? txtls: unreachable? txt: There is no file or directory  
    • ls [0-9].txt---a character in the specified range, and a numeric letter can be specified
        [[ email protected] ~]# ls [123].txt1.txt 2.txt 3.txt[[email protected] ~]# ls [0-3].txt1.txt 2.txt 3.txt[[emai l protected] ~]# ls [12].txt1.txt 2.txt[[email protected] ~]# ls [0-9a-za-z].txt1.txt 2.txt 3.txt a.txt 
    • ls {1,2}.txt---1 or 2.txt file
        [[email protected] ~]# ls {1,2,3,a}.txt1.txt 2.txt 3.txt a . txt  
Input and output redirection
  • Cat 1.txt > 2.txt erase 2.txt to input 1.txt content
  • Cat 1.txt >> 2.txt append 1.txt content to 2.txt
  • 2> Error Redirection
  • 2>> Error Append redirect
  • \>+2> equals &> correct and incorrect information redirected to
    [[email protected] ~]# echo 1212241 > a.txt[[email protected] ~]# ls [12].txt aaa.txt &> a.txt[[email protected] ~]# cat a.txt ls: 无法访问aaa.txt: 没有那个文件或目录1.txt2.txt
  • &>>---Correct and incorrect information append redirect
    [[email protected] ~]# ls [12].txt aaa.txt &>> a.txt[[email protected] ~]# cat a.txt ls: 无法访问aaa.txt: 没有那个文件或目录1.txt2.txtls: 无法访问aaa.txt: 没有那个文件或目录1.txt2.txt
  • Simultaneous use, correct error of the respective redirect, can also append
    [[email protected] ~]# ls [12].txt aaa.txt >1.txt 2> a.txt[[email protected] ~]# cat 1.txt1.txt2.txt[[email protected] ~]# cat a.txt ls: 无法访问aaa.txt: 没有那个文件或目录
  • < input redirection
    [[email protected] ~]# wc -l <1.txt    ---打印1.txt的行数,左边必须是命令2[[email protected] ~]# 2.txt < 1.txt-bash: 2.txt: 未找到命令
  • Command >1.txt 2>&1,
    The command command invokes the specified instruction and executes without querying the shell function, ignoring the function with the same name. The command command only executes commands inside the shell, which is equivalent to writing the correct and incorrect information to 1.txt, &1 equivalent to 1.txt

Shell introduction, History, aliases, wildcards and redirects

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.