0

to be more specific ,I want to display contents of files from output of find command,I tried the following commands but they don't get my work done

  • cat < find . -name "*.txt"
  • find . -name "*.txt" | cat
iruvar
  • 16,515
  • 8
  • 49
  • 81
user5844653
  • 3
  • 1
  • 2

2 Answers2

4

Either

find . -name "*.txt" | xargs cat --

or (better, if you have GNU find)

find . -name "*.txt" -print0 | xargs -0 cat --

or

find . -name "*.txt" -exec cat -- {} +
steeldriver
  • 78,509
  • 12
  • 109
  • 152
-1

You can use below the below command to display contents of files

Method 1:

find . -type f -iname "*.txt" -exec cat {} \;

Method 2:

ls -ltr *.txt | awk '{print "cat" " " $9}' | sh
Zanna
  • 3,491
  • 18
  • 28
Praveen Kumar BS
  • 5,139
  • 2
  • 9
  • 14
  • 1
    The second method has some issues. First `ls` behaves very differently on different OSs. Second building shell scripts on the run is a little bit of over doing it. – Raphael Ahrens Nov 24 '17 at 09:37