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 7637415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:56:01+00:00 2026-05-31T07:56:01+00:00

I have 1.2 million files split out into folders, like so: Everything ……….Folder 1

  • 0

I have 1.2 million files split out into folders, like so:

Everything
..........Folder 1
..................File 1
..................File 2
..................File 3
..................File 4
..................File 5 etc 
..........Folder 2
..................File 1
..................File 2
..................File 3
..................File 4
..................File 5 etc 

If I cd into Folder 1 I can run the following script to organize the files there into folders called 1, 2, 3, etc. of 1000 files each:

dir="${1-.}"
x="${2-1000}"

let n=0
let sub=0
while IFS= read -r file ; do
    if [ $(bc <<< "$n % $x") -eq 0 ] ; then
            let sub+=1
            mkdir -p "$sub"
            n=0
    fi

    mv "$file" "$sub"
    let n+=1
done < <(find "$dir" -maxdepth 1 -type f)

However I really would like to run it once on the Everything folder at the top level. From there it would consider the child folders, and do the by-1000 sorting so I could move everything out of Folder 1, Folder 2, etc. and into folders of 1000 items each called 1, 2, 3, etc.

Any ideas?

Edit: Heres how I would like the files to end up (as per comments):

Everything
..........Folder1
.................file1(these filenames can be anything, they shouldnt be renamed)
.................(every file in between so file2 > file 999)
.................file1000
..........Folder2  
.................file1001
.................(every file in between so file1002 > file file1999)
.................file2000

Every single possible file that is in the original folder structure is grouped into folders of 1000 items under the top level.

  • 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-31T07:56:02+00:00Added an answer on May 31, 2026 at 7:56 am

    Let’s assume your script is called organize.sh, and the Everything folder contains only directories. Try the following:

    cd Everything
    for d in *; do
        pushd $d
        bash ~/temp/organize.sh
        popd
    done
    

    Update

    To answer Tom’s question in the comment: you only need one copy of organize.sh. Say if you put it in ~/temp, then you can invoke as updated above.

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

Sidebar

Related Questions

I have over a million text files compressed into 40 zip files. I also
I have two 3GB text files, each file has around 80 million lines. And
I have over 5 million session files in /var/lib/php5 I would like to delete
I have several hundred files in a folder. Each of these file is a
I am doing PHP and have 11 million domains in text files loaded into
I have 3 million rows customers.csv file. When I import it in SQL 2008,
I have a rather large file (150 million lines of 10 chars). I need
I have a file with a little over a million lines. {<uri::rdfserver#null> <uri::d41d8cd98f00b204e9800998ecf8427e> <uri::TickerDailyPriceVolume>
I have a tab-separated data file with a little over 2 million lines and
I have a tab-delimited file that has over 200 million lines. What's the fastest

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.