|簡體中文

比思論壇

 找回密碼
 按這成為會員
搜索



查看: 579|回復: 5
打印 上一主題 下一主題

13个Cat命令管理(显示,排序,建立)文件实例

[複製鏈接]

25

主題

0

好友

292

積分

小學生

Rank: 2

  • TA的每日心情
    開心
    2023-8-10 12:40
  • 簽到天數: 131 天

    [LV.7]常住居民III

    推廣值
    0
    貢獻值
    0
    金錢
    623
    威望
    292
    主題
    25
    樓主
    發表於 2013-12-19 00:45:14
    1. 显示文件内容

    最简单的方法是直接输入‘cat file_name’.

    # cat /etc/issueCentOS release 5.10 (Final)Kernel \r on an \m2. 同时显示行号

    当在读取内容很多的配置文件时,如果同时显示行号将会使操作变简单,加上-n参数可以实现.

    # cat -n /etc/ntp.conf1 # Permit time synchronization our time resource but do not2 # permit the source to query or modify the service on this system3 restrict default kod nomodify notrap nopeer noquery4 restrict -6 default kod nomodify notrap nopeer noquery56 # Permit all access over the loopback interface. This could be7 # tightened as well, but to do so would effect some of the8 # administration functions9 restrict 127.0.0.110 restrict -6 ::13. 在非空格行首显示行号

    类似于-n参数,-b也可以显示行号。区别在于-b只在非空行前显示行号。

    #cat -b /etc/ntp.conf1 # Permit time synchronization our time resource but do not2 # permit the source to query or modify the service on this system3 restrict default kod nomodify notrap nopeer noquery4 restrict -6 default kod nomodify notrap nopeer noquery5 # Permit all access over the loopback interface. This could be6 # tightened as well, but to do so would effect some of the7 # administration functions8 restrict 127.0.0.19 restrict -6 ::14. 显示tab制表符

    当你想要显示文本中的tab制表位时. 可使用-T参数. 它会在输入结果中标识为 ^I .

    # cat -T /etc/hosts# Do not remove the following line, or various programs # that require network functionality will fail.127.0.0.1^I^Ilocalhost.localdomain localhost::1^I^Ilocalhost6.localdomain6 localhost65. 显示换行符

    -E参数在每行结尾使用 $ 表示换行符。如下所示 :

    # cat -E /etc/hosts# Do not remove the following line, or various programs$# that require network functionality will fail.$127.0.0.1 localhost.localdomain localhost$::1 localhost6.localdomain6 localhost6$6. 同时显示制表符及换行符

    当你想要同时达到-T及-E的效果, 可使用-A参数.

    # cat -A /etc/hosts# Do not remove the following line, or various programs$# that require network functionality will fail.$127.0.0.1^I^Ilocalhost.localdomain localhost$::1^I^Ilocalhost6.localdomain6 localhost6$7. 分屏显示

    当文件内容显示超过了你的屏幕大小, 可结合cat命令与其它命令分屏显示。使用管道符 ( | )来连接。

    # cat /proc/meminfo | less# cat /proc/meminfo | more

    在less与more显示结果的区别在于less参数可pageup及pagedown上下翻滚。而more仅能使用空格向下翻屏。

    8. 同时查看2个文件中的内容

    位于/root文件夹里有两个文件取名linux及desktop,每个文件含有以下内容 :

    Linux : Ubuntu, centos, RedHat, mint and slackware

    Desktop : gnome kde, xfce, enlightment, and cinnamon

    当你想同时查看两文件中的内容时,可按如下方法 :

    # cat /root/linux /root/desktopubuntucentosredhatmintslackwaregnomekdexfceenlightmentcinnamon
    無效樓層,該帖已經被刪除

    9

    主題

    0

    好友

    894

    積分

    高中生

    Rank: 4

  • TA的每日心情
    開心
    2021-11-4 09:01
  • 簽到天數: 118 天

    [LV.6]常住居民II

    推廣值
    0
    貢獻值
    0
    金錢
    2209
    威望
    894
    主題
    9
    板凳
    發表於 2014-3-13 12:33:40
    学习学习
    無效樓層,該帖已經被刪除
    5#
    無效樓層,該帖已經被刪除
    重要聲明:本論壇是以即時上載留言的方式運作,比思論壇對所有留言的真實性、完整性及立場等,不負任何法律責任。而一切留言之言論只代表留言者個人意見,並非本網站之立場,讀者及用戶不應信賴內容,並應自行判斷內容之真實性。於有關情形下,讀者及用戶應尋求專業意見(如涉及醫療、法律或投資等問題)。 由於本論壇受到「即時上載留言」運作方式所規限,故不能完全監察所有留言,若讀者及用戶發現有留言出現問題,請聯絡我們比思論壇有權刪除任何留言及拒絕任何人士上載留言 (刪除前或不會作事先警告及通知 ),同時亦有不刪除留言的權利,如有任何爭議,管理員擁有最終的詮釋權。用戶切勿撰寫粗言穢語、誹謗、渲染色情暴力或人身攻擊的言論,敬請自律。本網站保留一切法律權利。

    手機版| 廣告聯繫

    GMT+8, 2024-6-3 23:55 , Processed in 0.022286 second(s), 26 queries , Gzip On.

    Powered by Discuz! X2.5

    © 2001-2012 Comsenz Inc.

    回頂部