[root@localhost ~]# ls /root/.bash_history /root/.bash_history [root@localhost ~]# cat !$ cat /root/.bash_history init 0 ping www.baidu.com dhclient ping www.baidu.com yum install -y net-tools 等等等
[root@localhost ~]# history 1 init 0 2 ping www.baidu.com 3 dhclient 4 ping www.baidu.com 5 yum install -y net-tools 6 ifconfig
history命令shell
[root@localhost ~]# echo $HISTSIZE 1000 [root@localhost ~]#
history -c //把当前内存里面命令历史给清空vim
[root@localhost ~]# history -c [root@localhost ~]# history 1 history
但不会清空 .bash_history 配置文件,仅仅是把历史命令给清空
在敲完命令后,直接到配置文件中查看,会发现其中并无存在 这是由于仅存在内存中,只有在退出终端的时候,才可以保存到配置文件中去centos
HISTSIZE=5000
[root@localhost ~]# vim /etc/profile //在里面编辑文件,改变参数 改变参数后,能够重启终端,或者source /etc/profile,发现参数生效 [root@localhost ~]# source !$ //执行命令后,会发现HISTSIZE值变化了 source /etc/profile [root@localhost ~]# echo $HISTSIZE 5000
[root@localhost ~]# history 1 history 2 vim /etc/profile 3 yum provides "/*/vim" 4 yum install -y vim-enhanced 5 vim /etc/profile 6 source /etc/profile 7 echo $HISTSIZE 8 HISTIMEFORMAT="%Y/%m/%d %H:%M:%S" 9 history [root@localhost ~]# HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S" [root@localhost ~]# history 1 2017/11/15 23:25:28history 2 2017/11/15 23:35:08vim /etc/profile 3 2017/11/15 23:35:29yum provides "/*/vim" 4 2017/11/15 23:53:58yum install -y vim-enhanced 5 2017/11/15 23:59:04vim /etc/profile 6 2017/11/16 00:07:14source /etc/profile 7 2017/11/16 00:07:31echo $HISTSIZE 8 2017/11/16 00:13:45history 9 2017/11/16 00:14:49HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S" 10 2017/11/16 00:14:51history 11 [root@localhost ~]# echo $HISTTIMEFORMAT %Y/%m/%d %H:%M:%S
这个环境变量仅仅在当前窗口下的终端生效,在打开另外一个终端的时候,就会显示空的 也就是说,系统默认这个环境变量是不存在的
[root@hf-01 ~]# vim /etc/profile 进入配置文件中,在变量HISTSIZE下放入 HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S" 而后 :wq 保存退出 [root@hf-01 ~]# source !$ source /etc/profile
[root@hf-01 ~]# chattr +a ~/.bash_history [root@hf-01 ~]#
在运行不少命令后,未正常退出(exit或logout正常退出),直接关闭终端,那刚刚敲的命令就不会完整的保存到 .bash_history 中去bash
[root@hf-01 ~]# rpm -qa bash-completion //查看包是否安装完成 bash-completion-2.1-6.el7.noarch
[root@hf-01 ~]# systemctl restart network.service //重启网络服务 [root@hf-01 ~]# alias restartnet='systemctl restart network.service' [root@hf-01 ~]# restartnet //设置别名后,重启网络服务 [root@hf-01 ~]#
- 取消别名unalias - 在取消别名后,在输入别名,就会提示未找到命令
[root@hf-01 profile.d]# unalias restartnet [root@hf-01 profile.d]# restartnet -bash: restartnet: 未找到命令 [root@hf-01 profile.d]#
[root@hf-01 ~]# alias alias 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 restarnet='systemctl restart network.service' alias rm='rm -i' alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde' [root@hf-01 ~]#
[root@hf-01 ~]# ls 111 123 1_heard.txt 1_sorft.txt 234 2.txt.bak 3.txt anaconda-ks.cfg [root@hf-01 ~]# ls *.txt //以.txt结尾的文件都会列出来 1_heard.txt 1_sorft.txt 3.txt [root@hf-01 ~]# ls *txt //以txt结尾的文件都会列出来 1_heard.txt 1_sorft.txt 3.txt [root@hf-01 ~]# ls *txt* //包含txt的都会列出来 1_heard.txt 1_sorft.txt 2.txt.bak 3.txt [root@hf-01 ~]# ls 1* //只要1开头的都会列出来 1_heard.txt 1_sorft.txt 111: 123: [root@hf-01 ~]#
[root@hf-01 ~]# touch 1.txt 2.txt [root@hf-01 ~]# ls ?.txt 1.txt 2.txt 3.txt [root@hf-01 ~]# touch a.txt bb.txt [root@hf-01 ~]# ls ?.txt 1.txt 2.txt 3.txt a.txt [root@hf-01 ~]#
[root@hf-01 ~]# ls 111 1_heard.txt 1.txt 2.txt 3.txt a.txt 123 1_sorft.txt 234 2.txt.bak anaconda-ks.cfg bb.txt [root@hf-01 ~]# ls [0-3].txt 1.txt 2.txt 3.txt 能够把0,1,2,3这四个数字,任意一个都会知足这个条件,[]方括号中的字符只会取一个,就是“或者”的意思 [root@hf-01 ~]# ls [23].txt 2.txt 3.txt [root@hf-01 ~]# ls [13].txt 1.txt 3.txt 在方括号中能够写范围[0-9a-zA-Z]
[root@hf-01 ~]# ls {1,2,3}.txt 1.txt 2.txt 3.txt [root@hf-01 ~]# {1,2,3}.txt和[1-3].txt表达意思同样,或者。只是在{}须要用 , 逗号隔开
> 正确输出 >> 追加剧定向 2> 错误重定向 2>> 错误追加剧定向 >+2>等于&> 表示结合了正确和错误
[root@hf-01 ~]# laaa -bash: laaa: 未找到命令 [root@hf-01 ~]# laaa 2> a.txt [root@hf-01 ~]# cat a.txt -bash: laaa: 未找到命令 [root@hf-01 ~]#
[root@hf-01 ~]# ls [12].txt aaa.txt &> a.txt [root@hf-01 ~]# cat a.txt ls: 没法访问aaa.txt: 没有那个文件或目录 1.txt 2.txt [root@hf-01 ~]#
[root@hf-01 ~]# ls [12].txt aaa.txt &>> a.txt [root@hf-01 ~]# cat !$ cat a.txt ls: 没法访问aaa.txt: 没有那个文件或目录 1.txt 2.txt ls: 没法访问aaa.txt: 没有那个文件或目录 1.txt 2.txt
[root@hf-01 ~]# ls [12].txt aaa.txt >1.txt 2>a.txt [root@hf-01 ~]# cat 1.txt 1.txt 2.txt [root@hf-01 ~]# cat a.txt ls: 没法访问aaa.txt: 没有那个文件或目录
既能够写入一个文件中,也能够分开写入
[root@hf-01 ~]# wc -l < 1.txt 2 [root@hf-01 ~]# 2.txt < 1.txt -bash: 2.txt: 未找到命令 [root@hf-01 ~]#