shell基礎知識
history指令 檢視曆史記錄
[root@localhost ~]# history
1 echo $PATH
2 echo $LANG
3 locale
4 locale -a |grep zh
5 locale -a|grep zhhistory -c
6 locale
7 locale -a|grep zh
8 locale
9 yum groupinstall chinese-support
10 locale
echo $HISTSIZE 檢視可以記錄的曆史條數
[root@localhost ~]# echo $HISTSIZE
1000
history -c 清空曆史
HISTSIZE 在/etc/profile中定義
HOSTNAME=<code>/usr/bin/hostname 2&gt;/dev/null</code>
HISTSIZE=1000 我們可以修改這個數值,執行source /etc/profile
if [ "$HISTCONTROL" = "ignorespace" ] ; then
export HISTCONTROL=ignoreboth
else
export HISTCONTROL=ignoredups
fi
HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S " 定義時間
[root@localhost ~]# HISTTIMEFORMAT="%Y/%m%d %H:%M:%S "
[root@localhost ~]# echo $HISTTIMEFORMAT
%Y/%m%d %H:%M:%S
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
時間永久生效的做法:把定義的時間放到/etc/profile下
#vim /etc/profile
#HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S" 這條語句和#HISTSIZE=1000 放在一起
#:wq
#source /etc/profile
chattr +a ~/.bash_history 指令,記錄永遠儲存,不能被删除,隻能追加
!!表示執行上一條指令
[root@localhost ~]# pwd
/root
[root@localhost ~]# !!
pwd
!n 表示執行曆史中的第n條指令
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
!字元串表示曆史執行最近一條以字元串開頭的指令
tab 指令補全
alias 别名指令-把常用的長指令換成短指令
自定義别名 是在.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>錯誤重定向 >追加重定向 [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]# cat 1.tx cat: 1.tx: 沒有那個檔案或目錄 [root@localhost 10]# cat 1.txt 123
[root@localhost 10]# dddddd
-bash: dddddd: 未找到指令
[root@localhost 10]# dddddd 2> 1.txt
[root@localhost 10]# echo "12345" > 1.txt
12345
正确和錯誤的輸出 指定到一個檔案中
[root@localhost ~]# ls {1..3}.txt aaa.txt &>5.txt
[root@localhost ~]# cat 5.txt
ls: 無法通路aaa.txt: 沒有那個檔案或目錄
2.txt
3.txt
本文轉自 yzllinux部落格,原文連結: http://blog.51cto.com/12947851/2059645 如需轉載請自行聯系原作者