shell基本知识
shell基础知识history命令 查看历史记录
# history
1echo $PATH
2echo $LANG
3locale
4locale -a |grep zh
5locale -a|grep zhhistory -c
6locale
7locale -a|grep zh
8locale
9yum groupinstall chinese-support
10locale
echo $HISTSIZE查看可以记录的历史条数
# echo $HISTSIZE
1000
history -c清空历史
HISTSIZE 在/etc/profile中定义
HOSTNAME=/usr/bin/hostname 2>/dev/null
HISTSIZE=1000 我们可以修改这个数值,执行source /etc/profile
if [ "$HISTCONTROL" = "ignorespace" ] ; then
export HISTCONTROL=ignoreboth
else
export HISTCONTROL=ignoredups
fi
HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S "定义时间
# HISTTIMEFORMAT="%Y/%m%d %H:%M:%S "
# echo $HISTTIMEFORMAT
%Y/%m%d %H:%M:%S
# history
12018/0111 06:49:18 HISTTIMEFORMAT="%Y/%m%d %H:%M:%S "
22018/0111 06:49:41 echo $HISTTIMEFORMAT
32018/0111 06:49:58 history
时间永久生效的做法:把定义的时间放到/etc/profile下
#vim /etc/profile
#HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S"这条语句和#HISTSIZE=1000 放在一起
#:wq
#source /etc/profile
chattr +a ~/.bash_history命令,记录永远保存,不能被删除,只能追加
!!表示执行上一条指令
# pwd
/root
# !!
pwd
/root
!n表示执行历史中的第n条指令
# history
12018/01/11 06:49:18 HISTTIMEFORMAT="%Y/%m%d %H:%M:%S "
22018/01/11 06:49:41 echo $HISTTIMEFORMAT
32018/01/11 06:49:58 history
42018/01/11 06:53:55 vim /etc/profile
52018/01/11 06:56:34 source /etc/profile
62018/01/11 06:57:59 echo $HISTTIMEFORMAT
72018/01/11 06:58:06 history
82018/01/11 06:58:16 ls
92018/01/11 06:58:23 history
102018/01/11 07:06:22 chattr +a ~/.bash_history
112018/01/11 07:08:34 pwd
122018/01/11 07:10:03 history
# !8
ls
!字符串表示历史执行最近一条以字符串开头的指令
tab 命令补全
alias 别名命令-把常用的长命令换成短命令
自定义别名 是在.bashrcls/etc/profile.d/中定义
自定义的alias 放在~/.bashrc/
alias restartnet='systmectl restart network.service'
通配符
表示匹配零个或是多个字符
?匹配一个字符*
# touch {1..5}.txt
# ls
1.txt3.txt5.txt filenametest.txt
2.txt4.txtanaconda-ks.cfgtest.tar
# touch bb.txt
# touch cc.txt
# ls ?.txt
1.txt2.txt3.txt4.txt5.txt
# ls .txt
3.txt4.txt
重定向符号
表示输出重定向
错误重定向
>追加重定向
# mkdir /tmp/10
# cd /tmp/10
# echo "123" > 1.txt
# ls
1.txt
# vi 1.txt
# echo "123">> 1.txt
# ls
1.txt
# cat 1.tx
cat: 1.tx: 没有那个文件或目录
# cat 1.txt
123
123
# dddddd
-bash: dddddd: 未找到命令
# dddddd 2> 1.txt
# cat 1.txt
-bash: dddddd: 未找到命令
# echo "12345" > 1.txt
# cat 1.txt
12345
正确和错误的输出 指定到一个文件中
# ls {1..3}.txt aaa.txt &>5.txt
# cat 5.txt
ls: 无法访问aaa.txt: 没有那个文件或目录
1.txt
2.txt
3.txt
页:
[1]