Mac OS X,  Ubuntu,  Unix

Get Line Numbers With The Less Command

One of the great things about cat is that you can view the contents of a file with line numbers. You do so using the -n option, as follows:

cat -n ~/Desktop/myFile

Sometimes a file is too big to view though, so you can pipe the output to less, to combine some of the best features of each:

cat -n ~/Desktop/myFile | less

Obviously, the same thing would work with more:

cat -n ~/Desktop/myFile | less

You can also do something similar with the grep command and the -n option:

grep -n ^ ~/Desktop/myFile | less

Enjoy.