D
D
Demigodd2018-03-07 11:44:24
bash
Demigodd, 2018-03-07 11:44:24

How to loop through all directories starting from /home/.. and find *.txt files and show them with cat, including their directories?

Good afternoon, how to write a script that will go through all the folders and if in this folder, for example , folder1 , there is a text file, then display it on the screen via cat ?
Probably no one understood what I really need. Let's say there are such directories
/home/folder1/folder2/folder3
in folder2 there is a text file file.txt.
/home/folder1/folder2/file.txt
We need an example of a script that will iterate through all directories starting from /home/......
and find these *.txt files and at the END output
folder2 - file.txt - (what written inside file.txt) i.e.
Folder
Name - Text File Name - (what is written inside the text file)
The problem is that a folder or file can have any name. and I won't be able to use their names like in this script.
echo "folder2 - file.txt - $(cat file.txt)"

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Viktor Taran, 2018-03-07
@Demigodd

find . -type f -name "file.exe" -exec cat {} \;

P
pfg21, 2018-03-07
@pfg21

write a script that traverses the directory tree and displays what you need in the output stream.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question