Ubuntu – How to concatenate files found by the find command in bash

bashcommand line

Searching for files using the bash find command, I would like to concatenate the resulting files into a new file. For example, if the find command yields:

find . -name "configuration_dev.txt"

./tmp/configuration1/configuration_dev.txt
./tmp/configuration2/configuration_dev.txt

I would like to concatenate the contents of the two files into a new file directly as a bash command.

Best Answer

The command to achieve the desired result is:

find . -name "configuration_dev.txt" -exec cat > testing.txt {} +

A good explanation of the above line is provided here: What is meaning of {} + in find's -exec command?

Related Question