Is it possible with either find or ls to see, in a list of results, if any given entry is the nth result, what n is?

So, for example, pretend ls -l returns:

total 0
-rw-rw---- 1 bigdog bigdog 0 Jan  3 17:13 a
-rw-rw---- 1 bigdog bigdog 0 Jan  3 17:13 b
-rw-rw---- 1 bigdog bigdog 0 Jan  3 17:13 c

Is there a way to get ls to return 1,2,3 for files a,b,c respectively?

Or, find . -type f returns:


Any way to get something like:

1 ./a
2 ./b
3 ./c

I am aware of ls | wc -l and the like, but that is not what I'm looking for.

  • eh, same solution, but somewhat different problem – cfye14 Jan 4 '16 at 1:28
  • Not if you see the problem for what it is: "Run some command and get line numbers in output" – muru Jan 4 '16 at 1:29
  • but how would i go about finding that thread given my question, ie how did you find it? – cfye14 Jan 4 '16 at 1:30
  • Googled line number output site:unix.stackexchange.com (it was the last result on the first page.) The Stack Exchange site search is notoriously bad, Googling with a site restriction often yields better results. – muru Jan 4 '16 at 1:35
  • eh ok, i'll accept that – cfye14 Jan 4 '16 at 1:46

You can use the following command:

ls | nl
  • Thx. Can't upvote but what I'm looking for. – cfye14 Jan 4 '16 at 0:26

"cat -n" will add line numbers. E.g.: ls | cat -n

  • what i'm looking for, thx. probably could find this but my google query was awkward, i think. – cfye14 Jan 4 '16 at 0:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.