国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Linux > 正文

一個簡單的linux命令 cat

2019-10-26 18:49:41
字體:
來源:轉載
供稿:網友

cat命令的用途是連接文件或標準輸入并打印。這個命令常用來顯示文件內容,或者將幾個文件連接起來顯示,或者從標準輸入讀取內容并顯示,它常與重定向符號配合使用。

命令格式

cat [選項] [文件]…

命令功能

cat主要有三大功能:
1.一次顯示整個文件:cat filename
2.從鍵盤創建一個文件:cat > filename 只能創建新文件,不能編輯已有文件.
3.將幾個文件合并為一個文件:cat file1 file2 > file

命令參數

-A, –show-all 等價于 -vET
-b, –number-nonblank 對非空輸出行編號
-e 等價于 -vE
-E, –show-ends 在每行結束處顯示 $
-n, –number 對輸出的所有行編號,由1開始對所有輸出的行數編號
-s, –squeeze-blank 有連續兩行以上的空白行,就代換為一行的空白行
-t 與 -vT 等價
-T, –show-tabs 將跳格字符顯示為 ^I
-u (被忽略)
-v, –show-nonprinting 使用 ^ 和 M- 引用,除了 LFD 和 TAB 之外

使用實例

實例一:把 log2012.log 的文件內容加上行號后輸入 log2013.log 這個文件里

命令:
cat -n log2012.log log2013.log

輸出:

[root@localhost test]# cat log2012.log 2012-012012-02======[root@localhost test]# cat log2013.log 2013-012013-022013-03======[root@localhost test]# cat -n log2012.log log2013.log   1 2012-01  2 2012-02  3  4  5 ======  6 2013-01  7 2013-02  8  9  10 2013-03  11 ======[root@localhost test]#

實例二:把 log2012.log 和 log2013.log 的文件內容加上行號(空白行不加)之后將內容附加到 log.log 里。

命令:
cat -b log2012.log log2013.log log.log
輸出:

[root@localhost test]# cat -b log2012.log log2013.log log.log  1 2012-01  2 2012-02  3 ======  4 2013-01  5 2013-02  6 2013-03  7 ======[root@localhost test]#

實例三:把 log2012.log 的文件內容加上行號后輸入 log.log 這個文件里

[root@localhost test]# cat log.log [root@localhost test]# cat -n log2012.log > log.log[root@localhost test]# cat -n log.log   1 2012-01  2 2012-02  3  4  5 ======[root@localhost test]#

實例四:使用here doc來生成文件

輸出:

[root@localhost test]# cat >log.txt <<EOF> Hello> World> Linux> PWD=$(pwd)> EOF[root@localhost test]# ls -l log.txt -rw-r--r-- 1 root root 37 10-28 17:07 log.txt[root@localhost test]# cat log.txt HelloWorldLinuxPWD=/opt/soft/test[root@localhost test]#

說明:
注意粗體部分,here doc可以進行字符串替換。

備注:

tac (反向列示)
命令:
tac log.txt
輸出:

[root@localhost test]# tac log.txt PWD=/opt/soft/testLinuxWorldHello            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 皋兰县| 宁都县| 科技| 鄯善县| 莱芜市| 栾城县| 阿荣旗| 康平县| 辛集市| 咸宁市| 桃江县| 白河县| 长春市| 漳浦县| 马鞍山市| 渑池县| 平舆县| 鸡西市| 衡水市| 林甸县| 秦安县| 西贡区| 长沙市| 奉化市| 施甸县| 沁水县| 陕西省| 龙山县| 孟州市| 香港| 安化县| 宜丰县| 黎平县| 永和县| 依安县| 乌鲁木齐县| 延长县| 永嘉县| 黄山市| 平利县| 榕江县|