Run
Run

Reputation: 896

Is there a easy way to display all contents of all files with a recursive mode in one directory?

Provided that I have the following directory structure:

.
├── 2.txt
├── 3.txt
└── a
    └── 1.txt

Now I want to display all contents of all files in this directory, which considered recursion. The possible format displaying like bellow:

a/1.txt:

...the content of 1.txt

2.txt:

...the content of 2.txt

3.txt:

...the content of 3.txt

Upvotes: 0

Views: 38

Answers (1)

Inian
Inian

Reputation: 85620

You can use find command with -exec option to run the cat command on all the files listed, in your case, all the text files,

find  . -name "*.txt" -print -exec cat "{}" \;

Run this command from the top folder containing the files 2.txt and 3.txt it should display all your file contents with name as you needed.

Upvotes: 2

Related Questions