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