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

相关文章

Mac系统下卸载JAVA和JDK的步骤

《Mac系统下卸载JAVA和JDK的步骤》JDK是Java语言的软件开发工具包,它提供了开发和运行Java应用程序所需的工具、库和资源,:本文主要介绍Mac系统下卸载JAVA和JDK的相关资料,需... 目录1. 卸载系统自带的 Java 版本检查当前 Java 版本通过命令卸载系统 Java2. 卸载自定

基于Linux的ffmpeg python的关键帧抽取

《基于Linux的ffmpegpython的关键帧抽取》本文主要介绍了基于Linux的ffmpegpython的关键帧抽取,实现以按帧或时间间隔抽取关键帧,文中通过示例代码介绍的非常详细,对大家的学... 目录1.FFmpeg的环境配置1) 创建一个虚拟环境envjavascript2) ffmpeg-py

nginx启动命令和默认配置文件的使用

《nginx启动命令和默认配置文件的使用》:本文主要介绍nginx启动命令和默认配置文件的使用,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录常见命令nginx.conf配置文件location匹配规则图片服务器总结常见命令# 默认配置文件启动./nginx

Python并行处理实战之如何使用ProcessPoolExecutor加速计算

《Python并行处理实战之如何使用ProcessPoolExecutor加速计算》Python提供了多种并行处理的方式,其中concurrent.futures模块的ProcessPoolExecu... 目录简介完整代码示例代码解释1. 导入必要的模块2. 定义处理函数3. 主函数4. 生成数字列表5.

Linux脚本(shell)的使用方式

《Linux脚本(shell)的使用方式》:本文主要介绍Linux脚本(shell)的使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录概述语法详解数学运算表达式Shell变量变量分类环境变量Shell内部变量自定义变量:定义、赋值自定义变量:引用、修改、删

基于Python实现一个Windows Tree命令工具

《基于Python实现一个WindowsTree命令工具》今天想要在Windows平台的CMD命令终端窗口中使用像Linux下的tree命令,打印一下目录结构层级树,然而还真有tree命令,但是发现... 目录引言实现代码使用说明可用选项示例用法功能特点添加到环境变量方法一:创建批处理文件并添加到PATH1

Linux链表操作方式

《Linux链表操作方式》:本文主要介绍Linux链表操作方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、链表基础概念与内核链表优势二、内核链表结构与宏解析三、内核链表的优点四、用户态链表示例五、双向循环链表在内核中的实现优势六、典型应用场景七、调试技巧与

基于Python实现一个简单的题库与在线考试系统

《基于Python实现一个简单的题库与在线考试系统》在当今信息化教育时代,在线学习与考试系统已成为教育技术领域的重要组成部分,本文就来介绍一下如何使用Python和PyQt5框架开发一个名为白泽题库系... 目录概述功能特点界面展示系统架构设计类结构图Excel题库填写格式模板题库题目填写格式表核心数据结构

详解Linux中常见环境变量的特点与设置

《详解Linux中常见环境变量的特点与设置》环境变量是操作系统和用户设置的一些动态键值对,为运行的程序提供配置信息,理解环境变量对于系统管理、软件开发都很重要,下面小编就为大家详细介绍一下吧... 目录前言一、环境变量的概念二、常见的环境变量三、环境变量特点及其相关指令3.1 环境变量的全局性3.2、环境变

Linux系统中的firewall-offline-cmd详解(收藏版)

《Linux系统中的firewall-offline-cmd详解(收藏版)》firewall-offline-cmd是firewalld的一个命令行工具,专门设计用于在没有运行firewalld服务的... 目录主要用途基本语法选项1. 状态管理2. 区域管理3. 服务管理4. 端口管理5. ICMP 阻断