每天一個 Linux 命令(11):nl 命令
nl命令在linux系統中用來計算檔案中行號。nl 可以將輸出的檔案內容自動的加上行號!其預設的結果與 cat -n 有點不太一樣, nl 可以將行號做比較多的顯示設計,包括位數與是否自動補齊 0 等等的功能。
1.命令格式:
nl [選項]… [檔案]…
2.命令引數:
-b :指定行號指定的方式,主要有兩種:
-b a :表示不論是否為空行,也同樣列出行號(類似 cat -n);
-b t :如果有空行,空的那一行不要列出行號(預設值);
-n :列出行號表示的方法,主要有三種:
-n ln :行號在螢幕的最左方顯示;
-n rn :行號在自己欄位的最右方顯示,且不加 0 ;
-n rz :行號在自己欄位的最右方顯示,且加 0 ;
-w :行號欄位的佔用的位數。
-p 在邏輯定界符處不重新開始計算。
3.命令功能:
nl 命令讀取 File 引數(預設情況下標準輸入),計算輸入中的行號,將計算過的行號寫入標準輸出。 在輸出中,nl 命令根據您在命令列中指定的標誌來計算左邊的行。 輸入文字必須寫在邏輯頁中。每個邏輯頁有頭、主體和頁尾節(可以有空節)。 除非使用 -p 標誌,nl 命令在每個邏輯頁開始的地方重新設定行號。 可以單獨為頭、主體和頁尾節設定行計算標誌(例如,頭和頁尾行可以被計算然而文字行不能)。
4.使用例項:
例項一:用 nl 列出 log2012.log 的內容
命令:
nl log2012.log
輸出:
[root@localhost test]# nl log2012.log 1 2012-01 2 2012-02 3 ======[root@localhost test]#
說明:
檔案中的空白行,nl 不會加上行號
例項二:用 nl 列出 log2012.log 的內容,空本行也加上行號
命令:
nl -b a log2012.log
輸出:
[root@localhost test]# nl -b a log2012.log 1 2012-01 2 2012-02 3 4 5 ======[root@localhost test]#
例項3:讓行號前面自動補上0,統一輸出格式
命令:
輸出:
[root@localhost test]# nl -b a -n rz log2014.log 000001 2014-01 000002 2014-02 000003 2014-03 000004 2014-04 000005 2014-05 000006 2014-06 000007 2014-07 000008 2014-08 000009 2014-09 000010 2014-10 000011 2014-11 000012 2014-12 000013 ======= [root@localhost test]# nl -b a -n rz -w 3 log2014.log 001 2014-01 002 2014-02 003 2014-03 004 2014-04 005 2014-05 006 2014-06 007 2014-07 008 2014-08 009 2014-09 010 2014-10 011 2014-11 012 2014-12 013 =======
說明:
nl -b a -n rz 命令列號預設為六位,要調整位數可以加上引數 -w 3 調整為3位。
相關文章
- linux每日命令(12):nl命令Linux
- 每天一個Linux命令(6):rmdir命令Linux
- 每天一個Linux命令(5):rm命令Linux
- 每天一個Linux命令(2):shutdown命令Linux
- 每天一個 Linux 命令(12):more 命令Linux
- 每天一個 Linux 命令(16):which 命令Linux
- 每天一個linux命令(1):find命令之execLinux
- 每天一個Linux命令(1):xargsLinux
- 每天學一個 Linux 命令(15):manLinux
- 每天學一個 Linux 命令(13):touchLinux
- nl命令
- 每天學習一個Linux命令-目錄Linux
- 每天一個linux命令--持續更新中~~Linux
- linux每日命令(11):cat命令Linux
- 每天一個Linux命令-使用du檢視檔案大小Linux
- 學習一個 Linux 命令:shutdown 命令Linux
- 每天一個設計模式之命令模式設計模式
- 每天一個Linux命令之ps-檢視系統程式資訊Linux
- 11個炫酷的Linux終端命令大全Linux
- 學習一個 Linux 命令:pstreeLinux
- 每天一條Linux命令(24) ssh (遠端安全登入)Linux
- 11個讓你吃驚的Linux終端命令Linux
- Linux中11個比較實用的命令列Linux命令列
- linux最常用的20個命令(一)Linux
- 今天11月22日小雪,linux幾個有趣的命令Linux
- 【Linux命令】grep命令Linux
- Linux命令—–CP命令Linux
- 11 個鮮為人知卻超實用的 Linux 命令!Linux
- Linux簡單命令(一)Linux
- linux刪除資料夾命令是什麼 linux刪除一個目錄的命令Linux
- 6個有趣的Linux命令Linux
- Linux命令技巧之30個必會的命令技巧Linux
- 重新點亮linux 命令樹————幫助命令[一]Linux
- Linux的幾個新手必備的命令(一)Linux
- 如何用Linux的at命令安排一個任務Linux
- Linux命令(1)——xargs命令Linux
- Linux命令之lldptool命令Linux
- Linux命令篇 - sed 命令Linux
- Linux命令篇 - grep 命令Linux