Linux – Find files and echo content on shell

catfindlinux

Im trying to search all files within a directory by name and outputting the files' content onto the shell.

Currently I'm only getting a list of files

find -name '.htaccess' -type f


./dir1/.htaccess
./dir23/folder/.htaccess
...

But how can I output the content of each file instead. Thought of something like piping the filename to the cat-command.

Best Answer

Use cat within the -exec predicate of find:

find -name '.htaccess' -type f -exec cat {} +

This will output the contents of the files, one after another.

Related Question