Answer the question
In order to leave comments, you need to log in
Recursively iterating over files in folders and subfolders and putting their contents into a single text file?
Hello.
I have recently been working with Bash, so do not kick hard) The
question is this.
There was a need to recursively go through all the subfolders of the directory and put the contents of all files into one, indicating the current location and name.
So far, it turns out to collect the contents of the files in the current folder and place them in a text box, with the following script:
cd /home/myUser/Documents/repos/core/
for f in * ; do echo -E -- "$f" -- && pwd && cat -- "$f" ; done >> name.txt
Answer the question
In order to leave comments, you need to log in
As a result, he solved his own question, as he expected, using find.
Below is the code, suddenly someone will come in handy in the future, who will have a similar question.
#!/usr/bin/env bash
for file in `find /path/to/your/directory/ -type f -name "*"`
do
echo -E -- ${file} -- && cat -- ${file} ;
done > /path_to_your_new_file/nameFile.txt
it's not entirely clear what you want
, you need to combine "all contents" do I understand correctly that the question is about the files contained in the directories? i.e. all files are found in the given directory and below should be detached ?
If so then here
If you just need to merge all files and directories into one file with the ability to restore directories, then tar can do it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question