Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7690623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:26:24+00:00 2026-05-31T20:26:24+00:00

Inside my main folder, I have multiple sub-folders and each sub folder contains multiple

  • 0

Inside my main folder, I have multiple sub-folders and each sub folder contains multiple files. I want to merge these files in every sub-folder.

So I am trying to do something like this:

cd ../master-folder

for file in $( find . -name "*.txt" );
do
cat "all the text files in this sub folder" > "name of the subfolder.txt"
rm  "all the previous text files excluding the merged output obviously"
    done

Appreciate the help! Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T20:26:25+00:00Added an answer on May 31, 2026 at 8:26 pm

    I would do it like this, if the order of the files doesn’t matter :

    for i in $(find -maxdepth 1 -mindepth 1 -type d)
    do
        find $i -name '*.txt' -type f -exec cat {} >> $i-list.txt \;
        find $i -name '*.txt' -type f -exec rm {} \;
    done
    

    The first find looks for subdirectories.

    The second one appends all subfile’s content to a file

    The third one deletes the subfiles.

    This doesn’t work if there are recursive subdirectories. If you want this, remove ‘-maxdepth 1’

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a folder with several hundreds of folders inside it. These folders contain
I have different XML-files in my 'src/main/recources' folder, and I'd like to read them
How to exclude files from src/main/resources, for ex : I have a folder named
I have a structured path of folders (main->band name->album->mp3 files) and all of those
Scenario I have a Windows Forms Application. Inside the main form there is a
I have my main GUI thread, and a second thread running inside it's own
I have a main wrapper div that is set 100% width. Inside that i
I am trying to run all unit tests using eunit inside a folder but
I have a back up folder and a main folder in my project. I
I have a folder myApp1 and pom.xml is lying inside myApp1. Here is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.