I'm looking for a command like

find -name "*clang*" -exec cat {} \;


cat $(find -name "*clang*")

but giving me the file's path before each file's contents.

3 Answers 3


This has the advantage of spawning only one awk per run:

find . -type f -name '*clang*' -exec awk 'FNR==1{print FILENAME}1' {} +

Meaning of awk body:

  • FNR==1{print FILENAME}: For the first line of each file found, print its path.
  • 1: For each line, print it.

Try the following command:

find / -name "*clang*" -exec basename {} \; -exec cat {} \;

I found out that this is actually simpler than I thought:

find -name "*clang*" -print -exec cat {} \;
  • Although that would still try to run cat on any matching directories and other non-regular files. Also, it would require GNU find as other find implementations don't use the current directory by default if a search path isn't given.
    – Kusalananda
    May 25, 2020 at 22:39
  • For the first one, that's fine. For the second, a dot after find would solve that, right? May 25, 2020 at 22:42
  • Yes. And to only care about regular files, use -type f.
    – Kusalananda
    May 25, 2020 at 22:47

You must log in to answer this question.

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