Super User is a question and answer site for computer enthusiasts and power users. 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 am using

find some_dir -name "*.some_ext" | xargs -l10 grep "some_expr"

to find files in folder, but I just want to display the file name but not all file content. Any solution?

share|improve this question

grep -l (that's the lowercase letter L)

Also, I recommend:

find some_dir -name "*.some_ext" -print0 | xargs -0 -l 10 grep -l "some_expr"

That's just because I'm paranoid about file names. If you're going to use the output of grep to send to another program, you can use grep -lZ | xargs -0 some_command

share|improve this answer
Can you explain your command ? -print0 ? -0 -l ? Thanks ! – Foolish Mar 30 '11 at 15:14
The -print0 argument to find, -0 argument to xargs, and -Z argument to grep all refer to passing file-names using null termination, rather than carriage returns and line-feeds to separate filenames. This offers increased safety from files with unusual or malicious names. The man pages for each should give some details. – Slartibartfast Mar 31 '11 at 4:12

You can do this using grep alone:

grep -Rl --include=*.some_ext "some_expr" some_dir

where the letter following the R is a lower-case L.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .