Do you want to show line numbers in front of each line in a file in #Linux, #macOS, #FreeBSD or #Unix? Try

cat -n /etc/passwd

nl /etc/passwd

sed -n 3,5p /etc/resolv.conf | nl

See cyberciti.biz/faq/cat-line-num for more info.

Follow

@nixCraft The nl utility skips empty lines & restarts line numbers at the end of logical pages. If the file happens to have a "\:" line in it, nl will confuse its users. A better option for most terminals:

less -N /etc/resolv.conf

There's also the more/less replacement "most", which shows the cursor's line number in the status bar.

Sign in to participate in the conversation
Computer Fairies

Computer Fairies is a Mastodon instance that aims to be as queer, friendly and furry as possible. We welcome all kinds of computer fairies!