格式:cat 文件名
[root@model /]# cat /etc/resolv.conf # Generated by NetworkManagernameserver 10.198.1.1nameserver 8.8.8.8[root@model /]#
但是當文件內容比較多,超過一屏時,cat命令就不能滿足查看要求,就要用到more|less來查看
1.2、重定向輸入文件內容到新的文件[root@model Documents]# cat /etc/resolv.conf > a.txt[root@model Documents]# cat a.txt # Generated by NetworkManagernameserver 10.198.1.1nameserver 8.8.8.8[root@model Documents]#
一個">"表示清空文件,重新寫入新的內容,如果文件存在就清空,如果文件不存在就創建
二個">>"表示在文件末尾追加的末尾,如果文件存在就增加,如果文件不存在就創建
[root@model Documents]# cat /etc/httpd/conf.d/welcome.conf >>a.txt[root@model 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>[root@model Documents]#1.3 、重定向文件清空或者追加內容
[root@model Documents]# cat > a.txt<<gg> hello linux> gg[root@model Documents]# cat a.txt hello linux[root@model Documents]#
[root@model Documents]# cat >> a.txt <<fw> rrrrrrrrrrrrrr> QQqqqqqqq> wwwwwwwwwww> eeeeee> fw[root@model Documents]# cat a.txt hello linuxrrrrrrrrrrrrrrqqqqqqqqqwwwwwwwwwwweeeeee[root@model Documents]#
將2個標識符之間的肉寫入文件中,2個標識符可自定義,成對出現即可
一個">"表示清空文件,重新寫入新的內容,如果文件存在就清空,如果文件不存在就創建
二個">>"表示在文件末尾追加的末尾,如果文件存在就增加,如果文件不存在就創建
二、more/less格式: more/less 文件名
用于文件內容比較多時查看文件內容:用回車或者空格向下翻頁,按b向上翻頁,按q鍵退出
cat 翻頁功能因此經常和more命令搭配使用,cat命令還有就是將數個文件合并成一個文件的功能。more命令功能:讓畫面在顯示滿一頁時暫停,此時可按空格健繼續顯示下一個畫面,或按Q鍵停止顯示。less命令功能:less命令的用法與more命令類似,也可以用來瀏覽超過一頁的文件。所不同的是less命令除了可以按空格鍵向下顯示文件外,還可以利用上下鍵來卷動文件。當要結束瀏覽時,只要在less命令的提示符“:”下按Q鍵即可。其實這三個命令除了cat命令有合并文件的功能,其余功能上相近,只是從瀏覽習慣和顯示方式上有所不同。
三、grep是一種強大的文本搜索工具,它能使用正則表達式搜索文本,并把匹配的行打印出來
[root@model Documents]# grep -i "q" a.txt qqqqqqqqq[root@model Documents]# grep -iv "q" a.txt hello linuxrrrrrrrrrrrrrrwwwwwwwwwwweeeeee[root@model Documents]#四、vi

簡單命令:



簡單應用:
vi 文件名
按i鍵進行編輯
按ESC,:q退出不保存
按ESC,:q!退出不保存
按ESC,:wq退出保存
新聞熱點
疑難解答