亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Linux系統(tǒng)中cat命令使用的實例教程

開源中文社區(qū)   發(fā)布時間:2016-05-05 11:25:37   作者:hongchuntang   我要評論
這篇文章主要介紹了Linux系統(tǒng)中cat命令使用的實例教程,cat命令比較強大,除了顯示文件內(nèi)容,還可以新建需文件并向文件中追加內(nèi)容,要的朋友可以參考下

cat命令的主要作用是顯示一個文件的內(nèi)容,常與重定向符號>搭配使用.

主要使用方法
cat FILE 在Terminal中顯示文件的所有內(nèi)容.
cat > FILE 直接從Terminal中輸入文件內(nèi)容并創(chuàng)建文件.只能用于創(chuàng)建,不能修改已有文件.
cat FILE1 FILE2 > FILE 將多個文件內(nèi)容合并到一個文件里.

參數(shù)介紹
-v, --show-nonprinting 除了LFD和TAB之外,使用^和M-標(biāo)注.
-T, --show-tabs 將TAB顯示為^I.
-E, --show-ends 每行的末尾顯示$.
-A, --show-all 等同于-vET.
-n, --number 對所有行標(biāo)行號輸出.
-b, --numbernonblank 對于不為空的行標(biāo)行號顯示,會覆蓋-n.
-e 等同于-vE.
-s, --squeeze-blank 多個空行只顯示為一個空行.
-t 等同于-vT.
--help 顯示幫助信息.
--version 顯示版本信息.

技巧

1. 顯示文件內(nèi)容
最簡單的方法是直接輸入‘cat file_name’.

復(fù)制代碼
代碼如下:

# cat /etc/issue
CentOS release 5.10 (Final)
Kernel \r on an \m

2. 同時顯示行號
當(dāng)在讀取內(nèi)容很多的配置文件時,如果同時顯示行號將會使操作變簡單,加上-n參數(shù)可以實現(xiàn).

復(fù)制代碼
代碼如下:

# cat -n /etc/ntp.conf
1 # Permit time synchronization our time resource but do not
2 # permit the source to query or modify the service on this system
3 restrict default kod nomodify notrap nopeer noquery
4 restrict -6 default kod nomodify notrap nopeer noquery
5
6 # Permit all access over the loopback interface. This could be
7 # tightened as well, but to do so would effect some of the
8 # administration functions
9 restrict 127.0.0.1
10 restrict -6 ::1

3. 在非空格行首顯示行號
類似于-n參數(shù),-b也可以顯示行號。區(qū)別在于-b只在非空行前顯示行號。

復(fù)制代碼
代碼如下:

#cat -b /etc/ntp.conf
1 # Permit time synchronization our time resource but do not
2 # permit the source to query or modify the service on this system
3 restrict default kod nomodify notrap nopeer noquery
4 restrict -6 default kod nomodify notrap nopeer noquery
5 # Permit all access over the loopback interface. This could be
6 # tightened as well, but to do so would effect some of the
7 # administration functions
8 restrict 127.0.0.1
9 restrict -6 ::1

4. 顯示tab制表符
當(dāng)你想要顯示文本中的tab制表位時. 可使用-T參數(shù). 它會在輸入結(jié)果中標(biāo)識為 ^I .

復(fù)制代碼
代碼如下:

# 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 localhost6

5. 顯示換行符
-E參數(shù)在每行結(jié)尾使用 $ 表示換行符。如下所示 :

復(fù)制代碼
代碼如下:

# 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. 同時顯示制表符及換行符
當(dāng)你想要同時達到-T及-E的效果, 可使用-A參數(shù).

復(fù)制代碼
代碼如下:

# 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. 分屏顯示
當(dāng)文件內(nèi)容顯示超過了你的屏幕大小, 可結(jié)合cat命令與其它命令分屏顯示。使用管道符 ( | )來連接。

復(fù)制代碼
代碼如下:

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

在less與more顯示結(jié)果的區(qū)別在于less參數(shù)可pageup及pagedown上下翻滾。而more僅能使用空格向下翻屏。

8. 同時查看2個文件中的內(nèi)容
位于/root文件夾里有兩個文件取名linux及desktop,每個文件含有以下內(nèi)容 :

復(fù)制代碼
代碼如下:

Linux : ubuntu, centos, redhat, mint and slackware
Desktop : gnome kde, xfce, enlightment, and cinnamon

當(dāng)你想同時查看兩文件中的內(nèi)容時,可按如下方法 :

復(fù)制代碼
代碼如下:

# cat /root/linux /root/desktop
ubuntu
centos
redhat
mint
slackware
gnome
kde
xfce
enlightment
cinnamon

9. 排序顯示
類似. 你也可以結(jié)合cat命令與其它命令來進行自定義輸出. 如結(jié)合 sort ,通過管道符對內(nèi)容進行排序顯示。舉例 :

復(fù)制代碼
代碼如下:

# cat /root/linux | sort
centos
mint
redhat
slackware
Ubuntu

10. 輸入重定向
你也可將顯示結(jié)果輸出重定向到屏幕或另一個文件。 只需要使用 > 符號(大于號)即可輸出生成到另一個文件。

復(fù)制代碼
代碼如下:

# cat /root/linux > /root/linuxdistro

以上命令會生成一個與/root/linux內(nèi)容一模一樣的叫l(wèi)inuxdistro的文件.

11. 新建文件
Linux下有多種方法新建文件。其中使用cat就是方法之一.

復(fù)制代碼
代碼如下:

# cat > operating_system
Unix
Linux
Windows
MacOS

當(dāng)你輸入cat > operatingsystem,它會生成一個operatingsystem的文件。然后下面會顯示空行。此時你可輸入內(nèi)容。比如我們輸入Unix, Linux, Windows 和 MacOS, 輸入完成后,按Ctrl-D存盤退出cat。此時你會發(fā)現(xiàn)當(dāng)前文件夾下會生成一個包含你剛才輸入內(nèi)容的叫 operating_system的文件。

12.向文件中追加內(nèi)容
當(dāng)你使用兩個 > 符時, 會將第一個文件中的內(nèi)容追加到第二個文件的末尾。 舉例 :

復(fù)制代碼
代碼如下:

# cat /root/linux >> /root/desktop
# cat /root/desktop

它會將 /root/linux的內(nèi)容追加到/root/desktop文件的末尾。
第二個文件的內(nèi)容將會變成這樣:

復(fù)制代碼
代碼如下:

gnome
kde
xfce
enlightment
cinnamon
ubuntu
centos
redhat
mint
slackware

13. 重定向輸入
你可使用 <命令(小于號)將文件輸入到cat中.

復(fù)制代碼
代碼如下:

# cat < /root/linux

上面命令表示 /root/linux中的內(nèi)容作為cat的輸入。屏幕上顯示如下 :

復(fù)制代碼
代碼如下:

ubuntu
centos
redhat
mint
slackware

為了更清楚表示它的意義,我們使用以下命令 :

復(fù)制代碼
代碼如下:

# cat < /root/linux | sort > linux-sort

此命令這樣理解: 從/root/linux中讀取內(nèi)容,然后排序,將結(jié)果輸出并生成linux-sort新文件
然后我們看看linux-sort中的內(nèi)容 :

復(fù)制代碼
代碼如下:

centos
mint
redhat
slackware
ubuntu

以上是一些cat命令的日常基本應(yīng)用. 更多相關(guān)你可從cat命令手冊中學(xué)到并記得經(jīng)常練習(xí)它們.

相關(guān)文章

  • 詳解Linux中的cat文本輸出命令用法

    這篇文章主要介紹了Linux中的cat文本輸出命令用法,是Linux入門學(xué)習(xí)中的基礎(chǔ)知識,需要的朋友可以參考下
    2016-01-14
  • Linux下cat命令有哪些用途如何使用?

    如果要同時顯示多個文件的內(nèi)容,就要使用cat命令了,那么cat命令還有那些用途呢?下面一起來看看
    2014-12-09
  • linux下cat 命令使用詳解(顯示文件內(nèi)容)

    cat命令的用途是連接文件或標(biāo)準(zhǔn)輸入并打印。這個命令常用來顯示文件內(nèi)容,或者將幾個文件連接起來顯示,或者從標(biāo)準(zhǔn)輸入讀取內(nèi)容并顯示,它常與重定向符號配合使用
    2014-04-07
  • linux cat命令使用方法

    Linux Cat命令的一般用法這里我就不在提了,在baidu就可以直接收到相關(guān)資料,這里就不說了,下面談?wù)凩inux Cat命令的使用方法
    2012-11-14
  • Linux cat命令參數(shù)

    使用方式:cat [-AbeEnstTuv] [--help] [--version] fileName 說明:把檔案串連接后傳到基本輸出(螢?zāi)换蚣?> fileName 到另一個檔案) 參數(shù): -n 或 --number 由
    2008-11-28
  • linux下cat命令詳解

    cat命令的用途是連接文件或標(biāo)準(zhǔn)輸入并打印。這個命令常用來顯示文件內(nèi)容,或者將幾個文件連接起來顯示,或者從標(biāo)準(zhǔn)輸入讀取內(nèi)容并顯示,它常與重定向符號配合使用
    2016-06-05

最新評論