linux命令之nl

1.nl 介绍

linux命令nl用来将输出的文件内容自动加上行号

2.nl用法

nl [参数] filename

nl常用参数

参数

说明

-b a

输出内容都加上行号

-b t

只有非空行的输出加上行号,默认选项

-n ln

在最左方加上行号

-n rn

在最右方加上行号,且不加0

-n rz

在最右方加上行号,且加0

-w

行号字段占用的字符数,默认为6位数

3.实例

3.1.显示/etc/issue文件的内容

命令:

nl /etc/issue

[root@centos79-3 ~]# nl /etc/issue
     1	\S
     2	Kernel \r on an \m
       
[root@centos79-3 ~]#

3.2.输出/etc/issue文件内容都加上行号

命令:

nl -b a /etc/issue

[root@centos79-3 ~]# nl -b a /etc/issue
     1	\S
     2	Kernel \r on an \m
     3	
[root@centos79-3 ~]#

3.3.输出/etc/issue文件内容,并在最左方加上行号

命令:

nl -n ln /etc/issue

[root@centos79-3 ~]# nl -n ln /etc/issue
1     	\S
2     	Kernel \r on an \m
       
[root@centos79-3 ~]#

3.4.输出/etc/issue文件内容,并在最右方加上行号(不加0)

命令:

nl -n rn /etc/issue

[root@centos79-3 ~]# nl -n rn /etc/issue
     1	\S
     2	Kernel \r on an \m
       
[root@centos79-3 ~]#

3.5.输出/etc/issue文件内容,并在最右方加上行号(加0)

命令:

nl -n rz /etc/issue

[root@centos79-3 ~]# nl -n rz /etc/issue
000001	\S
000002	Kernel \r on an \m
       
[root@centos79-3 ~]#

3.6.输出/etc/issue文件内容,并在最右方加上行号(加0),且字段位数为4位

命令:

nl -n rz -w 4 /etc/issue

[root@centos79-3 ~]# nl -n rz -w 4 /etc/issue
0001	\S
0002	Kernel \r on an \m
     
[root@centos79-3 ~]#