Shell Basics (top)

Source: Internet
Author: User
Tags aliases time and date egrep

Shell Introduction


1. Other Shell:zsh,ksh

[[email protected] ~]# yum list | grep zshzsh.x86_64                                5.0.2-28.el7                 installedautojump-zsh.noarch                       22.3.0-3.el7                 epelzsh-html.x86_64                           5.0.2-28.el7                 basezsh-lovers.noarch                         0.9.0-1.el7                  epel[[email protected] ~]# yum list | grep kshksh.x86_64                                20120801-34.el7              basemksh.x86_64                               46-5.el7                     basepython-XStatic-Rickshaw.noarch            1.5.0.0-4.el7                epelpython-moksha-common.noarch               1.2.3-2.el7                  epelpython-moksha-hub.noarch                  1.5.3-2.el7                  epelpython-moksha-wsgi.noarch                 1.2.2-2.el7                  epel
Command history


1. Storage Address:

[[email protected] ~]# ls /root/.bash_history/root/.bash_history[[email protected] ~]# cat !$cat /root/.bash_historywhich lsecho $PATHwhereis lsyum installl -y locateyum installl -y mlocateyum install -y mlocatelocate

2. Store up to 1000 bars, controlled by scalar:

[[email protected] ~]# echo $HISTSIZE1000

3.HISTORY-C command:

清空内存里面命令历史,但是配置文件里面无法清空

4. When you exit the terminal, the memory saved history command will be written to the configuration file.
5. Modify the variable histsize:

[[email protected] ~]# vi /etc/profileHOSTNAME=`/usr/bin/hostname 2>/dev/null`HISTSIZE=1000if [ "$HISTCONTROL" = "ignorespace" ] ; then    export HISTCONTROL=ignoreboth

6. After the change is completed, the following command is required to take effect:

[[email protected] ~]# source /etc/profile

7. Let the saved history command have a specific time and date:
Temporary modification

[[email protected] ~]# HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S"[[email protected] ~]# echo $HISTTIMEFORMAT%Y/%m/%d %H:%M:%S[[email protected] ~]# history    1  2018/01/10 15:51:53history    2  2018/01/10 15:52:05cat .bash_history    3  2018/01/10 15:53:01history    4  2018/01/10 15:56:06vi /etc/profile    5  2018/01/10 15:57:46echo $HISTSIZE    6  2018/01/10 16:00:59HISTTIMEFORMAT=%Y%m%d %H:%M:%S    7  2018/01/10 16:01:29HISTTIMEFORMAT=%Y/%m/%d %H:%M:%S    8  2018/01/10 16:01:55HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S"    9  2018/01/10 16:02:13echo $HISTTIMEFORMAT   10  2018/01/10 16:02:19history

Permanently modified
Modifying profile profiles: Modifying variables to configuration files

vim /etc/profileHOSTNAME=`/usr/bin/hostname 2>/dev/null`HISTSIZE=1000HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S"[[email protected] ~]# echo $H

Then log back in to the terminal
8.!! Represents the previous command
9.! n indicates how many commands to run

  308  2018/01/10 17:21:54source /etc/profile  309  2018/01/10 17:27:01ls  310  2018/01/10 17:27:41history[[email protected] ~]# !309ls111  1.txt   2_hard.txt  2.txt.bak.bak  4.txt              apr-1.4.5123  1.txt~  2_soft.txt  3.txt          anaconda-ks.cfg.1  apr-1.4.5.tar.gz

10.! Command: In command history, look for the first command that starts with the command.

Command completion and aliases

1.CENTOS7 Support Command options: New packages need to be installed Bash-completion

[[email protected] ~]# yum install -y bash-completion已加载插件:fastestmirrorfile:///mnt/repodata/repomd.xml: [Errno 14] curl#37 - "Couldn‘t open file /mnt/repodata/repomd.xml"正在尝试其它镜像。Loading mirror speeds from cached hostfile正在解决依赖关系--> 正在检查事务---> 软件包 bash-completion.noarch.1.2.1-6.el7 将被 安装--> 解决依赖关系完成

Restart the system after installation reboot
2.alias aliases

[[email protected] ~]# alias restartnet=‘systemctl restart network.service‘        #建立别名[[email protected] ~]# restartnet

See what aliases are available

[[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‘

3. Place alias: In the following two places

[[email protected] ~]# vi .bashrc
[[email protected] ~]# cd /etc/profile.d

4. Alias: Unalias

[[email protected] ~]# unalias restartnet[[email protected] ~]# resreset       resize2fs   resizecons  resizepart  restorecon  [[email protected] ~]# resreset       resize2fs   resizecons  resizepart  restorecon  [[email protected] ~]# restartnet-bash: restartnet: 未找到命令
Wildcard, input and output redirection

*  表示任意数量任意字符
?代表任意一个字符
[1-3].txt      代表一个范围
{1,2}.txt         代表一个范围
>        把前一个命令的输出输入到后面文件中去,会把后面文件内容清空重写
>>          追加,不会删除后面文件内容
2>         把命令产生的错误信息输入到一个文件中去[[email protected] ~]# lsaaa 2> 2.txt[[email protected] ~]# cat 2.txt-bash: lsaaa: 未找到命令
2>>      错误追加重定向[[email protected] ~]# lsaaa 2>> 2.txt[[email protected] ~]# cat 2.txt-bash: lsaaa: 未找到命令-bash: lsaaa: 未找到命令
&>          把错误和正确信息都输入到一个文件[[email protected] ~]# ls [12].txt aaa.txt &>a.txt[[email protected] ~]# cat a.txtls: 无法访问aaa.txt: 没有那个文件或目录2.txt
&>>       把错误和正确信息都追加到一个文件
可以把正确和错误的分开存放[[email protected] ~]# ls [12].txt aaa.txt >1.txt 2>a.txt[[email protected] ~]# cat 1.txt2.txt[[email protected] ~]# cat a.txtls: 无法访问aaa.txt: 没有那个文件或目录
<        输入重定向[[email protected] ~]# wc -l 2.txt > 1.txt[[email protected] ~]# cat 1.txt2 2.txt[[email protected] ~]# wc -l < 1.txt1[[email protected] ~]# wc -l 1.txt1 1.txt

Shell Basics (top)

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.