Linux 「less」コマンドで行番号を表示する

Linux 「less」コマンドで行番号を表示する

Linuxで、「less」コマンドで行番号を表示する手順を記述してます。

環境

  • OS Rocky Linux release 8.4 (Green Obsidian)

行番号を表示

「less」コマンド実行時に行番号を表示するには、オプション「-N」を使用します。

例えば「httpd.conf」を「less」コマンドで行番号を表示して、確認する場合は以下となります。

less -N httpd.conf

実行結果

ちなみに「cat」の場合は「-n」となります。

cat -n httpd.conf

<出力結果>
     1  #
     2  # This is the main Apache HTTP server configuration file.  It contains the
     3  # configuration directives that give the server its instructions.
     4  # See <URL:http://httpd.apache.org/docs/2.4/> for detailed information.
     5  # In particular, see 
     6  # <URL:http://httpd.apache.org/docs/2.4/mod/directives.html>
     7  # for a discussion of each configuration directive.
     8  #
     9  # See the httpd.conf(5) man page for more information on this configuration,
    10  # and httpd.service(8) on using and configuring the httpd service.
    11  #
    12  # Do NOT simply read the instructions in here without understanding
    13  # what they do.  They're here only as hints or reminders.  If you are unsure
    14  # consult the online docs. You have been warned.  
    15  #

「nl」コマンドも、行番号を表示してくれます。

nl httpd.conf

<出力結果>
     1  #
     2  # This is the main Apache HTTP server configuration file.  It contains the
     3  # configuration directives that give the server its instructions.
     4  # See <URL:http://httpd.apache.org/docs/2.4/> for detailed information.
     5  # In particular, see 
     6  # <URL:http://httpd.apache.org/docs/2.4/mod/directives.html>
     7  # for a discussion of each configuration directive.
     8  #
     9  # See the httpd.conf(5) man page for more information on this configuration,
    10  # and httpd.service(8) on using and configuring the httpd service.
    11  #
    12  # Do NOT simply read the instructions in here without understanding