Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

2 Answers

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
add comment

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
add comment

Your Answer

 
discard

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.