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
2 ## httpd.conf -- Apache HTTP server configuration file
6 # Based upon the NCSA server configuration files originally by Rob McCool.
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
↑Blank lines are not counted as lines