Linux 系统中,nl命令用于计算文件中的行号

2024-05-12 20:52

本文主要是介绍Linux 系统中,nl命令用于计算文件中的行号,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

在 Linux 系统中,nl命令用于计算文件中的行号。它可以将输出的文件内容自动加上行号,并且可以通过不同的选项来设置行号的显示方式,包括行号的位数、是否自动补齐 0 等。其命令格式为:nl(选项)…(文件)…。以下是一些常见的选项:

  • -b:指定行号指定的方式,主要有两种:
    • -b a:表示不论是否为空行,也同样列出行号(类似cat -n)。
    • -b t:如果有空行,空的那一行不要列出行号(默认值)。
  • -n:列出行号表示的方法,主要有三种:
    • -n ln:行号在屏幕的最左方显示。
    • -n rn:行号在屏幕的最右方显示,且行号从 1 开始计数。
    • -n rn:行号在屏幕的最右方显示,且行号从 0 开始计数。
nl -b t /etc/selinux/config1  # This file controls the state of SELinux on the system.2  # SELINUX= can take one of these three values:3  #     enforcing - SELinux security policy is enforced.4  #     permissive - SELinux prints warnings instead of enforcing.5  #     disabled - No SELinux policy is loaded.6  SELINUX=enforcing7  # SELINUXTYPE= can take one of three values:8  #     targeted - Targeted processes are protected,9  #     minimum - Modification of targeted policy. Only selected processes are protected.10  #     mls - Multi Level Security protection.11  SELINUXTYPE=targetednl -n rz /etc/selinux/config000001  # This file controls the state of SELinux on the system.
000002  # SELINUX= can take one of these three values:
000003  #     enforcing - SELinux security policy is enforced.
000004  #     permissive - SELinux prints warnings instead of enforcing.
000005  #     disabled - No SELinux policy is loaded.
000006  SELINUX=enforcing
000007  # SELINUXTYPE= can take one of three values:
000008  #     targeted - Targeted processes are protected,
000009  #     minimum - Modification of targeted policy. Only selected processes are protected.
000010  #     mls - Multi Level Security protection.
000011  SELINUXTYPE=targeted


 

以下是使用nl命令的一些示例:

  1. 基本用法:

隐藏过程

plaintext

   (root@centos79 test3)# cat a.txte38idfae83sggj2ztycgsgsa(root@centos79 test3)# nl a.txt1 e2 383 i4 d5 f6 a7 e8 839 s10 g11 g12 j13 214 z15 t16 y17 c18 g19 s20 g21 s22 a

  1. -n rz选项:行号在屏幕的最右方显示,且行号从 0 开始计数。

隐藏过程

plaintext

   (root@centos79 test3)# cat a.txte38idfae83sggj2ztycgsgsa(root@centos79 test3)# nl -n rz a.txt0 e1 382 i3 d4 f5 a6 e7 838 s9 g10 g11 j12 213 z14 t15 y16 c17 g18 s19 g20 s21 a

  1. -w选项:指定行号的宽度。

隐藏过程

plaintext

   (root@centos79 test3)# cat a.txte38idfae83sggj2ztycgsgsa(root@centos79 test3)# nl -n rz a.txt001 e002 38003 i004 d005 f006 a007 e008 83009 s010 g011 g012 j013 2014 z015 t016 y017 c018 g019 s020 g021 s022 a

  1. -b选项:指定行号的显示方式。

隐藏过程

plaintext

   (root@centos79 test3)# cat a.txte38idfae83sggj2ztycgsgsa(root@centos79 test3)# nl -b a a.txt1 e2 383 i4 d5 f6 a7 e8 839 s10 g11 g12 j13 214 z15 t16 y17 c18 g19 s20 g21 s22 a

plaintext

   (root@centos79 test3)# cat a.txte38idfae83sggj2ztycgsgsa(root@centos79 test3)# nl -b t a.txt1 e2 383 i4 d5 f6 a7 e8 839 s10 g11 g12 j13 214 z15 t16 y17 c18 g19 s20 g21 s22 a
 ls | nl1  adjtime2  aliases3  aliases.db4  alternatives5  anacrontab6  asound.conf7  audisp8  audit9  bash_completion.d10  bashrc
 jps -l | nl1  4448 org.apache.zookeeper.server.quorum.QuorumPeerMain2  4622 sun.tools.jps.Jps
ps -ef | nl1  UID         PID   PPID  C STIME TTY          TIME CMD2  root          1      0  0 19:14 ?        00:00:04 /usr/lib/systemd/systemd --switched-root --s                                                                        ystem --deserialize 223  root          2      0  0 19:14 ?        00:00:00 [kthreadd]4  root          3      2  0 19:14 ?        00:00:02 [ksoftirqd/0]5  root          5      2  0 19:14 ?        00:00:00 [kworker/0:0H]6  root          7      2  0 19:14 ?        00:00:00 [migration/0]7  root          8      2  0 19:14 ?        00:00:00 [rcu_bh]8  root          9      2  0 19:14 ?        00:00:03 [rcu_sched]
 ps aux | nl1  USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND2  root          1  0.3  0.3 128168  6760 ?        Ss   19:14   0:04 /usr/lib/systemd/systemd --switched-root --system --deserialize 223  root          2  0.0  0.0      0     0 ?        S    19:14   0:00 [kthreadd]4  root          3  0.1  0.0      0     0 ?        S    19:14   0:02 [ksoftirqd/0]5  root          5  0.0  0.0      0     0 ?        S<   19:14   0:00 [kworker/0:0H]6  root          7  0.0  0.0      0     0 ?        S    19:14   0:00 [migration/0]7  root          8  0.0  0.0      0     0 ?        S    19:14   0:00 [rcu_bh]8  root          9  0.2  0.0      0     0 ?        S    19:14   0:03 [rcu_sched]9  root         10  0.0  0.0      0     0 ?        S<   19:14   0:00 [lru-add-drain]10  root         11  0.2  0.0      0     0 ?        S    19:14   0:03 [watchdog/0]

这篇关于Linux 系统中,nl命令用于计算文件中的行号的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/983708

相关文章

nginx -t、nginx -s stop 和 nginx -s reload 命令的详细解析(结合应用场景)

《nginx-t、nginx-sstop和nginx-sreload命令的详细解析(结合应用场景)》本文解析Nginx的-t、-sstop、-sreload命令,分别用于配置语法检... 以下是关于 nginx -t、nginx -s stop 和 nginx -s reload 命令的详细解析,结合实际应

Linux线程之线程的创建、属性、回收、退出、取消方式

《Linux线程之线程的创建、属性、回收、退出、取消方式》文章总结了线程管理核心知识:线程号唯一、创建方式、属性设置(如分离状态与栈大小)、回收机制(join/detach)、退出方法(返回/pthr... 目录1. 线程号2. 线程的创建3. 线程属性4. 线程的回收5. 线程的退出6. 线程的取消7.

C#连接SQL server数据库命令的基本步骤

《C#连接SQLserver数据库命令的基本步骤》文章讲解了连接SQLServer数据库的步骤,包括引入命名空间、构建连接字符串、使用SqlConnection和SqlCommand执行SQL操作,... 目录建议配合使用:如何下载和安装SQL server数据库-CSDN博客1. 引入必要的命名空间2.

Linux下进程的CPU配置与线程绑定过程

《Linux下进程的CPU配置与线程绑定过程》本文介绍Linux系统中基于进程和线程的CPU配置方法,通过taskset命令和pthread库调整亲和力,将进程/线程绑定到特定CPU核心以优化资源分配... 目录1 基于进程的CPU配置1.1 对CPU亲和力的配置1.2 绑定进程到指定CPU核上运行2 基于

golang程序打包成脚本部署到Linux系统方式

《golang程序打包成脚本部署到Linux系统方式》Golang程序通过本地编译(设置GOOS为linux生成无后缀二进制文件),上传至Linux服务器后赋权执行,使用nohup命令实现后台运行,完... 目录本地编译golang程序上传Golang二进制文件到linux服务器总结本地编译Golang程序

Linux下删除乱码文件和目录的实现方式

《Linux下删除乱码文件和目录的实现方式》:本文主要介绍Linux下删除乱码文件和目录的实现方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录linux下删除乱码文件和目录方法1方法2总结Linux下删除乱码文件和目录方法1使用ls -i命令找到文件或目录

Linux在线解压jar包的实现方式

《Linux在线解压jar包的实现方式》:本文主要介绍Linux在线解压jar包的实现方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录linux在线解压jar包解压 jar包的步骤总结Linux在线解压jar包在 Centos 中解压 jar 包可以使用 u

linux解压缩 xxx.jar文件进行内部操作过程

《linux解压缩xxx.jar文件进行内部操作过程》:本文主要介绍linux解压缩xxx.jar文件进行内部操作,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、解压文件二、压缩文件总结一、解压文件1、把 xxx.jar 文件放在服务器上,并进入当前目录#

Linux系统性能检测命令详解

《Linux系统性能检测命令详解》本文介绍了Linux系统常用的监控命令(如top、vmstat、iostat、htop等)及其参数功能,涵盖进程状态、内存使用、磁盘I/O、系统负载等多维度资源监控,... 目录toppsuptimevmstatIOStatiotopslabtophtopdstatnmon

PowerShell中15个提升运维效率关键命令实战指南

《PowerShell中15个提升运维效率关键命令实战指南》作为网络安全专业人员的必备技能,PowerShell在系统管理、日志分析、威胁检测和自动化响应方面展现出强大能力,下面我们就来看看15个提升... 目录一、PowerShell在网络安全中的战略价值二、网络安全关键场景命令实战1. 系统安全基线核查