標籤:
一、cat1.1、查看檔案內容
格式:cat 檔案名稱
[[email protected] /]# cat /etc/resolv.conf # Generated by NetworkManagernameserver 10.198.1.1nameserver 8.8.8.8[[email protected] /]#
但是當檔案內容比較多,超過一屏時,cat命令就不能滿足查看要求,就要用到more|less來查看
1.2、重新導向輸入檔案內容到新的檔案
[[email protected] Documents]# cat /etc/resolv.conf > a.txt[[email protected] Documents]# cat a.txt # Generated by NetworkManagernameserver 10.198.1.1nameserver 8.8.8.8[[email protected] Documents]#
一個">"表示清空檔案,重新寫入新的內容,如果檔案存在就清空,如果檔案不存在就建立
二個">>"表示在檔案末尾追加的末尾,如果檔案存在就增加,如果檔案不存在就建立
[[email protected] Documents]# cat /etc/httpd/conf.d/welcome.conf >>a.txt[[email protected] Documents]# cat a.txt # Generated by NetworkManagernameserver 10.198.1.1nameserver 8.8.8.8# # This configuration file enables the default "Welcome"# page if there is no default index page present for# the root URL. To disable the Welcome page, comment# out all the lines below.#<LocationMatch "^/+$"> Options -Indexes ErrorDocument 403 /error/noindex.html</LocationMatch>[[email protected] Documents]#
1.3 、重新導向檔案清空或者追加內容
[[email protected] Documents]# cat > a.txt<<gg> hello linux> gg[[email protected] Documents]# cat a.txt hello linux[[email protected] Documents]#
[[email protected] Documents]# cat >> a.txt <<fw> rrrrrrrrrrrrrr> qqqqqqqqq> wwwwwwwwwww> eeeeee> fw[[email protected] Documents]# cat a.txt hello linuxrrrrrrrrrrrrrrqqqqqqqqqwwwwwwwwwwweeeeee[[email protected] Documents]#
將2個標識符之間的肉寫入檔案中,2個標識符可自訂,成對出現即可
一個">"表示清空檔案,重新寫入新的內容,如果檔案存在就清空,如果檔案不存在就建立
二個">>"表示在檔案末尾追加的末尾,如果檔案存在就增加,如果檔案不存在就建立
二、more/less
格式: more/less 檔案名稱
用於檔案內容比較多時查看檔案內容:用斷行符號或者空格向下翻頁,按b向上翻頁,按q鍵退出
cat 翻頁功能因此經常和more命令搭配使用,cat命令還有就是將數個檔案合并成一個檔案的功能。
more命令功能:讓畫面在顯示滿一頁時暫停,此時可按空格健繼續顯示下一個畫面,或按Q鍵停止顯示。
less命令功能:less命令的用法與more命令類似,也可以用來瀏覽超過一頁的檔案。所不同的是less命令除了可以按空格鍵向下顯示檔案外,還可以利用上下鍵來捲動檔案。當要結束瀏覽時,只要在less命令的提示符“:”下按Q鍵即可。
其實這三個命令除了cat命令有合并檔案的功能,其餘功能上相近,只是從瀏覽習慣和顯示方式上有所不同。
三、grep
是一種強大的文本搜尋工具,它能使用Regex搜尋文本,並把匹配的行列印出來
[[email protected] Documents]# grep -i "q" a.txt qqqqqqqqq[[email protected] Documents]# grep -iv "q" a.txt hello linuxrrrrrrrrrrrrrrwwwwwwwwwwweeeeee[[email protected] Documents]#
四、vi
簡單命令:
簡單應用:
vi 檔案名稱
按i鍵進行編輯
按ESC,:q退出不儲存
按ESC,:q!退出不儲存
按ESC,:wq退出儲存
Linux對檔案內容基本操作(學習筆記七)