鍍金池/ 教程/ Linux/ nl命令
which命令
ss命令
cp命令使用示例
ps命令
find命令
grep命令
scp命令
rmdir命令
df命令示例
less命令
du命令示例
chown命令示例
route命令
ping命令
more命令
mv命令
ln命令
mkdir命令
rm命令
find命令常用參數(shù)示例
cat命令
find命令-xargs參數(shù)
touch命令
traceroute命令
gzip命令示例
date命令
ls命令
vmstat命令
lsof命令
diff命令
head命令
watch命令
ifconfig命令
cd命令
tail命令
iostat命令
chgrp命令示例
free命令
find命令-exec參數(shù)
tar命令打包解壓示例
cal命令
at命令
netstat命令
wc命令
chmod命令示例
pwd命令
top命令詳解示例
crontab命令(Linux定時(shí)任務(wù))
whereis命令
Linux命令大全教程
nl命令
rcp命令
locate命令

nl命令

nl命令在linux系統(tǒng)中用來計(jì)算文件中行號。nl可以將輸出的文件內(nèi)容自動的加上行號!其默認(rèn)的結(jié)果與 cat -n 有點(diǎn)不太一樣, nl 可以將行號做比較多的顯示設(shè)計(jì),包括位數(shù)與是否自動補(bǔ)齊 0 等等的功能。

1.命令格式

nl [選項(xiàng)]… [文件]…

2.命令參數(shù)

  • -b :指定行號指定的方式,主要有兩種:
  • -b a :表示不論是否為空行,也同樣列出行號(類似 cat -n);
  • -b t :如果有空行,空的那一行不要列出行號(默認(rèn)值);
  • -n :列出行號表示的方法,主要有三種:
  • -n ln :行號在螢?zāi)坏淖钭蠓斤@示;
  • -n rn :行號在自己欄位的最右方顯示,且不加 0 ;
  • -n rz :行號在自己欄位的最右方顯示,且加 0 ;
  • -w :行號欄位的占用的位數(shù)。
  • -p 在邏輯定界符處不重新開始計(jì)算。

3.命令功能

nl 命令讀取 File 參數(shù)(缺省情況下標(biāo)準(zhǔn)輸入),計(jì)算輸入中的行號,將計(jì)算過的行號寫入標(biāo)準(zhǔn)輸出。 在輸出中,nl 命令根據(jù)您在命令行中指定的標(biāo)志來計(jì)算左邊的行。 輸入文本必須寫在邏輯頁中。每個邏輯頁有頭、主體和頁腳節(jié)(可以有空節(jié))。 除非使用 -p 標(biāo)志,nl 命令在每個邏輯頁開始的地方重新設(shè)置行號??梢詥为?dú)為頭、主體和頁腳節(jié)設(shè)置行計(jì)算標(biāo)志(例如,頭和頁腳行可以被計(jì)算然而文本行不能)。

4.使用實(shí)例

實(shí)例一

nl 列出 log.log 的內(nèi)容
命令:

nl log.log

輸出:

[yiibai@localhost test]$ cat log.log
this is line 1.
this is line 2.
this is line 3.
this is line 4.

this is line 5.

-----------------end
[yiibai@localhost test]$ nl log.log
     1  this is line 1.
     2  this is line 2.
     3  this is line 3.
     4  this is line 4.

     5  this is line 5.

     6  -----------------end
[yiibai@localhost test]$

說明:文件中的空白行,nl 不會加上行號。

實(shí)例二

nl 列出 log.log 的內(nèi)容,空本行也加上行號。
命令:

nl -b a log.log

輸出:

[yiibai@localhost test]$ nl -b a log.log
     1  this is line 1.
     2  this is line 2.
     3  this is line 3.
     4  this is line 4.
     5
     6  this is line 5.
     7
     8  -----------------end
[yiibai@localhost test]$

實(shí)例三

讓行號前面自動補(bǔ)上0,統(tǒng)一輸出格式。

[yiibai@localhost test]$ nl -b a -n rz log.log
000001  this is line 1.
000002  this is line 2.
000003  this is line 3.
000004  this is line 4.
000005
000006  this is line 5.
000007
000008  -----------------end
[yiibai@localhost test]$ nl -b a -n rz -w 3 log.log
001     this is line 1.
002     this is line 2.
003     this is line 3.
004     this is line 4.
005
006     this is line 5.
007
008     -----------------end
[yiibai@localhost test]$

說明:nl -b a -n rz 命令行號默認(rèn)為六位,要調(diào)整位數(shù)可以加上參數(shù) -w 3 調(diào)整為3位。