Usually with grep -r "word" <path> you see:

<file_path>: <line_with_word>

but if you did something like:

find . -type f -name "*.py" -exec grep "word" {} \;

You can see only the content, with grep -l you can only see the file, and I want both.

1 Answer 1


If you’re using GNU grep, the -H option will ensure that the output is prefixed with the filename in all cases:

find . -type f -name "*.py" -exec grep -H "word" {} \;

Incidentally, you could use + here instead of \; to run grep on as many files as possible at a time:

find . -type f -name "*.py" -exec grep -H "word" {} +

You must log in to answer this question.

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