shell基础(上)
生活随笔
收集整理的這篇文章主要介紹了
shell基础(上)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
一 shell介紹
shell 是一個命令解釋器。本質上是用戶與計算機之間的交互。
用戶把指令告訴shell,然后shell再傳輸給系統內核,接著內核再去支配計算機硬件去執行各種操作。
每個用戶都可以有自己特定的shell。
CentOS7默認shell為bash(Bourne Again Shell)。
還有zsh,ksh等。
[root@localhost ~]# yum list|grep zsh zsh.x86_64 5.0.2-28.el7 base zsh-html.x86_64 5.0.2-28.el7 base?
二 命令歷史
執行過的命令都會記錄。這些命令保存在用戶的家目錄的.bash_history文件中。
注意: 只有當用戶退出當前shell時,在當前shell中運行的命令才會保存在.bash_history文件中。
?
運行命令
[root@localhost ~]# history顯示命令歷史,結果如下:
可以記錄1000條命令歷史( 變量HISTSIZE)。
[root@localhost ~]# echo $HISTSIZE 1000在/etc/profile中修改。
與命令歷史有關的一個特殊字符!
常見應用:
- !! :執行上一條指令。
- !n : 執行命令歷史中的第n條指令
- !word(字符串 大于等于1):執行最近一次以word開頭的命令。
?
三 通配符
?* ?匹配0個或多個字符。
? 匹配1個字符。
實例如下:
1 匹配*
[root@localhost /]# cd tmp [root@localhost tmp]# ls 1 3.txt 11 systemd-private-4c298191af864cd1a3f133883d308ceb-vmtoolsd.service-xr6HDH 12.tar test 13.tar.gz test.zip 1.txt yum_save_tx.2018-01-09.22-27.7kaeYH.yumtx 1.txt.zip zsh-5.0.2-28.el7.x86_64.rpm 2.txt [root@localhost tmp]# ls *.txt 1.txt 2.txt 3.txt2 匹配?
[root@localhost tmp]# ls ?.txt 1.txt 2.txt 3.txt [root@localhost tmp]# ls ?.zip ls: 無法訪問?.zip: 沒有那個文件或目錄3 [0-9] ?表示范圍,或的關系。 ?{1,2}或的關系。
[root@localhost tmp]# ls [0-9].txt 1.txt 2.txt 3.txt [root@localhost tmp]# ls {1,2}.txt 1.txt 2.txt?
四 輸入/輸出重定向
< ?輸入重定向
> 輸出重定向 ?將命令的結果輸入到文件中。
2> 錯誤重定向
>> 追加重定向
?
實例如下:
[root@localhost tmp]# echo "123">1.txt //輸出重定向 [root@localhost tmp]# echo "123">>1.txt //追加輸出 [root@localhost tmp]# cat 1.txt 123 123[root@localhost tmp]# wc -l < 1.txt //輸入重定向 2 [root@localhost tmp]#?
轉載于:https://my.oschina.net/primerliu/blog/1605363
總結
以上是生活随笔為你收集整理的shell基础(上)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux 操作系统基础知识
- 下一篇: java中demo接人_return的用