What does the -n option do in the cat command?

The -n option in the cat command is used to number all output lines. When you use this option, each line of the output will be prefixed with its corresponding line number, starting from 1.

Example:

cat -n filename.txt

This command will display the contents of filename.txt, with each line numbered. For instance, if filename.txt contains:

Hello, World!
This is a test file.
It has multiple lines.

The output with the -n option will look like this:

     1  Hello, World!
     2  This is a test file.
     3  It has multiple lines.

This option is useful for easily referencing specific lines in a file, especially when dealing with longer texts.

0 Comments

no data
Be the first to share your comment!