日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

shell基础(上)

發布時間:2023/12/19 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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中修改。


與命令歷史有關的一個特殊字符

常見應用:

  • !! :執行上一條指令。
[root@localhost ~]# !! ls -l /etc/profile //上一條指令 -rw-r--r--. 1 root root 1795 11月 6 2016 /etc/profile
  • !n : 執行命令歷史中的第n條指令
[root@localhost ~]# !723 ls /usr/local/apache2/ bin cgi-bin error icons lib man modules build conf htdocs include logs manual
  • !word(字符串 大于等于1):執行最近一次以word開頭的命令。
[root@localhost ~]# !723 ls /usr/local/apache2/ bin cgi-bin error icons lib man modules build conf htdocs include logs manual [root@localhost ~]# !ls ls /usr/local/apache2/ bin cgi-bin error icons lib man modules build conf htdocs include logs manual

?

三 通配符

?* ?匹配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.txt

2 匹配?

[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基础(上)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。