To display line numbers when using the cat
command in Linux or Unix, you can use the -n
option.
Here is the basic syntax for using the cat
command with the -n
option:
cat -n file
This will display the contents of file
with line numbers added to the beginning of each line.
For example, to display the contents of the file test.txt
with line numbers, you can use the following command:
cat -n test.txt
This will output the contents of test.txt
with line numbers, like this:
1 This is the first line of the file. 2 This is the second line of the file. 3 This is the third line of the file.
You can also use the -b
option to display line numbers for non-empty lines only, like this:
cat -b file
For more information on using the cat
command and its options, you can consult the cat
manual or seek guidance from the Linux or Unix community.