I have lots of directories in a certain directory and I am trying to find a specific file present in there. I used grep command recursively and was able to locate the file being present in there, but I don't know where it is present exactly. So, how can I use cat on that file to display the contents of that file?

PS- I finally got it. I was doing it all wrong. Thanks for the replies.

closed as unclear what you're asking by Jeff Schaller Jun 13 at 17:33

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 5
    grep recursive should print the file path by default. What options did you use? – muru Jun 13 at 12:36
  • 2
    you tagged find; did you use find in combination with grep somehow? How? – Jeff Schaller Jun 13 at 12:43
  • 2
    You wrote "I used grep command recursively and was able to locate the file being present in there". To make it more clear what you want, I suggest to edit your question and show the command(s) you used. – Bodo Jun 13 at 13:02

Use below command

find  path -type f -iname "filename" -exec cat {} \;

I am not 100% what you want, but consider the following:

grep -Rl pattern | xargs cat

grep -l will print only the file location relative to your current working directory, while xargs will redirect it to cat thus instantly printing the content of the file(s) found.

  • until the pattern is in a file named with spaces... – Jeff Schaller Jun 13 at 17:34

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