How can I print contents instead of file name from using linux find command?

The find utility deals with pathnames. If no specific action is mentioned in the find command for the found pathnames, the default action is to output them.

You may perform an action on the found pathnames, such as running cat, by adding -exec to the find command:

find . -type f -name 'cbs_cdr_vou_20180615*.unl' -exec cat {} + >/home/fifa/cbs/test.txt

This would find all regular files in or under the current directory, whose names match the given pattern. For as large batches of these as possible, cat would be called to concatenate the contents of the files.

The output would go to /home/fifa/cbs/test.txt.

Related:

  • Understanding the -exec option of `find`

The output of find will result with the relevant file names.
You can pipe (|) the output to xargs cat which will perform the cat command on each file.

e.g.:

find -type f -name 'cbs_cdr_vou_20180615*.unl' | xargs cat  > /home/fifa/cbs/test.txt

Another option will be to use -exec cat

find -type f -name 'cbs_cdr_vou_20180615*.unl'  -exec cat {} \;  > /home/fifa/cbs/test.txt

Tags:

Linux

Find

Cat