0

View a file with line numbers

grep -n ^ /path/to/file | less

November 9, 2011bashoneliners

Explanation

  • grep ^ will match all lines in a file
  • grep -n will prefix each line of output with the line number within its input file

Limitations

In some systems you might have to use egrep instead of grep.

Alternative one-liners

1

View a file with line numbers

cat -n /path/to/file | less

February 13, 2012openiduser28