shell介紹
shell是一個指令解釋器,提供使用者和機器之間的互動,支援特定文法,比如邏輯判斷、循環,每個使用者都可以有自己特定的shell
CentOS7預設shell為bash(Bourne Agin Shell)
還有zsh、ksh等
指令曆史
檢視曆史指令
[root@test76 ~]# cat .bash_history
修改曆史記錄條數:
vi /etc/profile
HISTSIZE=1000
修改檢視曆史記錄的格式:
/etc/profile中新增:
HISTTIMEFORMAT="%Y/%m/%d %H:%M:%S "
source /etc/profile
841 2017/10/20 06:01:05 vi .bash_history
842 2017/10/20 06:02:03 vi /etc/profile
843 2017/10/20 06:03:23 source /etc/profile
844 2017/10/20 06:03:27 history
加入權限控制:
[root@test76 ~]# chattr +a .bash_history
[root@test76 ~]# > .bash_history
-bash: .bash_history: Operation not permitted
!!:表示執行上條指令
!844:表示執行844行的指令
!his:表示執行his開頭的指令,是最近一次執行的his開頭的
指令補全和别名
1、tab補全
2、參數補全 安裝bash-completion
alias 别名
[root@test ~]# alias wo='ls /root' #臨時有效
[root@test ~]# wo
2.txt 2.txt.bz2 anaconda-ks.cfg
永久有效:
[root@test ~]# vi .bashrc
# .bashrc
# User specific aliases and functions
alias wo='ls /root'
通配符
1、[root@test ~]# ls *.txt
2.txt david.txt
2、
[root@test ~]# ls ?.txt
2.txt
[root@test ~]# ls ??.txt
23.txt
[root@test ~]# ls [0-9].txt
[root@test ~]# ls [0-9][0-9].txt
[root@test ~]# ls {2,23}.txt
23.txt 2.txt
重定向:
cat 1.txt >2.txt
cat 1.txt >> 2.txt
[root@test ~]# cat 23.txt >> 2.txt &>/dev/null
本文轉自 jiekegz 51CTO部落格,原文連結:http://blog.51cto.com/jacksoner/1978471