Click here for "Error Codes for Commercial Air Conditioners".(Japanese Version)

Display the contents of a file with line numbers

Display the contents of a file with line numbers

To display the contents of a file, use the cat command, but if you run it without options, it will simply display the contents. To display the contents of a file with line numbers, run the cat command with the option '-n'.
If you don't want to add line numbers to blank lines in the file, add the option "-b".

●Display the contents of a file with line numbers

[nuy@Lion conf]$ cat -n httpd.conf
1 ##
2 ## httpd.conf -- Apache HTTP server configuration file
3 ##
4
5 #
6 # Based upon the NCSA server configuration files originally by Rob McCool.
7 #
8 # This is the main Apache server configuration file. It contains the
9 # configuration directives that give the server its instructions.
10 # See for detailed information about
11 # the directives.
↑Display the contents of the "httpd.conf" file with line numbers.

●If you don't want to add line numbers to blank lines

[nuy@lion conf]$ cat -b httpd.conf

[nuy@lion conf]$ cat -b httpd.conf
1 ##
2 ## httpd.conf -- Apache HTTP server configuration file
3 ##

4 #
5 # Based upon the NCSA server configuration files originally by Rob McCool.
6 #
7 # This is the main Apache server configuration file. It contains the
8 # configuration directives that give the server its instructions.
9 # See for detailed information about
10 # the directives.

↑Blank lines are not counted as lines

Copied title and URL