shell介绍、命令历史、补全和别名、通配符、重定向
shell介绍shell是一个命令解释器,提供用户和机器之间的交互
支持特定语法,比如逻辑判断、循环
每个用户都可以有自己特定的shell
CentOS7默认shell为bash(Bourne Agin Shell)
还有zsh、ksh等
命令历史
history命令
-d 行号删除该行
# vi /root/.bash_history//history命令存放文件
.bash_history
# echo $HISTSIZE//变量HISTSIZE最大1000条
1000
# history -c//清空内存命令历史
# history -w//保存文件到文件里去
# vi /etc/profile// /etc/profile中修改HISTSIZE
# source /etc/profile
HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S "
# HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S "
# echo $HISTTIMEFORMAT
%Y/%m/%d %H:%M:%S
# history
622017/10/26 21:34:47 history
632017/10/26 21:34:57 vi /etc/profile
642017/10/26 21:36:31 echo $HISTSIZE
# chattr +a /root/.bash_history
永久保存 chattr +a ~/.bash_history
!! 执行历史命令最后一个命令
!n 执行历史命令的某个命令(n数字)
!word历史命令从下往上找以word开头的第一个命令
命令补全和别名
tab键
敲一下:命令补全
敲两下:列出以某些字符开头的命令
参数补全,安装bash-completion
# yum install -y bash-completion
# reboot//重启
# rpm -q bash-completion
bash-completion-2.1-6.el7.noarch
alias别名给命令重新起个名字
# alias resrenet='systemctl restart network'
各用户都有自己配置别名的文件 ~/.bashrc
# vi .bashrc
其他的别名所在
ls /etc/profile.d/
# ls /etc/profile.d/
自定义的alias放到~/.bashrc
通配符
ls *.txt
# ls *.sh//*通配.sh结尾的脚本文件
256term.sh colorgrep.shlang.shvim.sh
bash_completion.shcolorls.sh less.shwhich2.sh
# ls *.cs*//不分字符、不分几个
256term.csh colorls.cshless.cshwhich2.csh
ls ?.txt
# ls *.?sh//一个任意的字符
256term.csh colorls.cshless.cshwhich2.csh
ls .txt
# ls .txt//0-2任意一个都满足
1.txt2.txt
ls {1,2}.txt
# ls {0,1,2}.txt//大括号里的必须要有,没有会报错。类似但是要,隔开
ls: 无法访问0.txt: 没有那个文件或目录
1. txt2.txt
输入输出重定向
cat 1.txt >2.txt
# echo "22">2.txt
# echo "11">1.txt
# cat 1.txt > 2.txt重定向覆盖
# cat 2.txt
11
cat 1.txt >> 2.txt
# cat 2.txt
11
# echo "22">1.txt
# cat 1.txt >> 2.txt //追加重定向
# cat 2.txt
11
22
ls aaa.txt 2>err
# ls aaa.txt 2>1.txt//2错误重定向
# cat 1.txt
ls aaa.txt 2>>err
# cat 1.txt
ls: 无法访问aaa.txt: 没有那个文件或目录
# ls aaa.txt 2>>1.txt //错误追加重定向
# cat 1.txt
ls: 无法访问aaa.txt: 没有那个文件或目录
ls: 无法访问aaa.txt: 没有那个文件或目录
# > >> 2> 2>> >+2>=== &>
# ls {1,3,2,0}.txt &> >lsx.txt //正确输出和错误输出都到lsx.txt里去
# cat lsx.txt
ls: 无法访问3.txt: 没有那个文件或目录
ls: 无法访问0.txt: 没有那个文件或目录
1.txt
2.txt
wc -l < 1.txt
# cat 1.txt
ls: 无法访问aaa.txt: 没有那个文件或目录
ls: 无法访问aaa.txt: 没有那个文件或目录
# wc -l < 1.txt //输入重定向
2
command >1.txt 2>&1
# ls {1,3,2,0}.txt >> lsx.txt 2>>lshx.txt //正确的输入到lsx.txt 错误的输入到lshx.txt
# cat lshx.txt
ls: 无法访问3.txt: 没有那个文件或目录
ls: 无法访问0.txt: 没有那个文件或目录
页:
[1]