Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to know a handy command to search for some strings in multiple plain text files and show the line number where it matchs in the output. ie:

grep -r 'hello' --include=*.js ¿?


base.js  [4]
base.js  [13]
utils.js [27]


share|improve this question
up vote 2 down vote accepted

Use -n as an option to grep. Or combine them in one with recursive mode, e.g.:

grep -rn pattern path/to/folder

As the manpage of grep says:

   -n, --line-number
          Prefix  each  line of output with the 1-based line number
          within its input file.  (-n is specified by POSIX.)

Example output:

temp/openssh/openssh-6.0p1/sshconnect2.c:1468:  sent = send_pubkey_test(authctxt, id);
                                         ||||----- Line number
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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