# Split folder into dvd size

**URL:** <https://community.unix.com/t/split-folder-into-dvd-size/247839>\
**Category:** Shell Programming and Scripting\
**Created:** [August 25, 2009, 12:20pm UTC](https://community.unix.com/t/split-folder-into-dvd-size/247839 "2009-08-25T12:20:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![cabrao](https://community.unix.com/letter_avatar/cabrao/32/6_449c533f586939b6e5f246632a46421f.png) [@cabrao](https://community.unix.com/u/cabrao)\
**Post date:** [August 25, 2009, 12:20pm UTC](https://community.unix.com/t/split-folder-into-dvd-size/247839/1 "2009-08-25T12:20:54Z")

</div>

Hello everyone,

I have a big folder in a linux server that contains dozen of big files (total folder size ~ 50 GB)

I have a couple of files of 2.5 GB and some others from 100 MB to 1 GB. (that said it's obvious that it's impossible having two 2.5 GB files in one dvd)

The purpose is to backup all files and burn them into DVD but I would like to maximize each dvd's size so I'm trying to to create a script to split that folder into a couple of folders named DVD1, DVD2, ..., DVDN but I don't have the scripting knowledge needed for this.

Can someone help me please?

Thanks in advance.

Regards,

---

<div class="post-metadata">

**Author:** ![chompy](https://community.unix.com/letter_avatar/chompy/32/6_449c533f586939b6e5f246632a46421f.png) [@chompy](https://community.unix.com/u/chompy)\
**Post date:** [August 25, 2009, 12:28pm UTC](https://community.unix.com/t/split-folder-into-dvd-size/247839/2 "2009-08-25T12:28:25Z")

</div>

> **[how to split a file](https://www.unix.com/unix-for-dummies-questions-and-answers/55337-how-split-file.html)**
>
> Hi everyone, please forgive my ignorance but I am trying to split a large data file into smaller manageable chunks. The file is approx 1GB in size (maybe a little more). I want to split it into 4 file | The UNIX and Linux Forums

---

<div class="post-metadata">

**Author:** ![cabrao](https://community.unix.com/letter_avatar/cabrao/32/6_449c533f586939b6e5f246632a46421f.png) [@cabrao](https://community.unix.com/u/cabrao)\
**Post date:** [August 26, 2009, 7:12am UTC](https://community.unix.com/t/split-folder-into-dvd-size/247839/3 "2009-08-26T07:12:46Z")

</div>

Thanks for your fast answer chompy, but I believe my question is different.

The purpose of my thread is not to split a file or multiple files but split or divide a folder into multiple dvd size folders (about 4.3 GB )

Any idea/help please?

Many thanks

---

<div class="post-metadata">

**Author:** ![cfajohnson](https://community.unix.com/user_avatar/community.unix.com/cfajohnson/32/16669_2.png) [@cfajohnson](https://community.unix.com/u/cfajohnson)\
**Post date:** [August 26, 2009, 12:12pm UTC](https://community.unix.com/t/split-folder-into-dvd-size/247839/4 "2009-08-26T12:12:12Z")

</div>

Try the bin-pack script from Chapter 13 of my book, Shell Scripting Recipes. The scripts are available at [http://cfaj.freeshell.org/shell/ssr/ssr-scripts.tar.gz](http://cfaj.freeshell.org/shell/ssr/ssr-scripts.tar.gz)

Change the size in the variable bin\_size.

---

<div class="post-metadata">

**Author:** ![cabrao](https://community.unix.com/letter_avatar/cabrao/32/6_449c533f586939b6e5f246632a46421f.png) [@cabrao](https://community.unix.com/u/cabrao)\
**Post date:** [August 27, 2009, 4:11am UTC](https://community.unix.com/t/split-folder-into-dvd-size/247839/5 "2009-08-27T04:11:02Z")

</div>

Thanks for your answer cfajohnson, however I forgot to mention that I cannot split my files, in other words I just want to divide a big folder and arrange their files into multiple mini folders (max mini folder size about 4.3 GB - dvd size)

Example: Lets say that I have 5 files in a folder:

folder  
file1 2.5 GB  
file2 2.5 GB  
file3 100 MB  
file4 500 MB  
file5 2.0 GB

The script will check files in the initial folder and will create and move the necessary into new folders (max size about 4.3 GB)

Desired output in this case would be:  
folder1

- file1 2.5 GB
- file3 100 MB
- file4 500 MB

folder2

- file2 2.5 GB

folder3

- file5 2.0 GB

Any help? Thanks

---

<div class="post-metadata">

**Author:** ![cfajohnson](https://community.unix.com/user_avatar/community.unix.com/cfajohnson/32/16669_2.png) [@cfajohnson](https://community.unix.com/u/cfajohnson)\
**Post date:** [August 27, 2009, 4:42pm UTC](https://community.unix.com/t/split-folder-into-dvd-size/247839/6 "2009-08-27T16:42:27Z")

</div>

The program I mentioned doesn't split files unless they are larger than the maximum size, and that can easily be disabled.

---

<div class="post-metadata">

**Author:** ![cabrao](https://community.unix.com/letter_avatar/cabrao/32/6_449c533f586939b6e5f246632a46421f.png) [@cabrao](https://community.unix.com/u/cabrao)\
**Post date:** [September 4, 2009, 8:47am UTC](https://community.unix.com/t/split-folder-into-dvd-size/247839/7 "2009-09-04T08:47:46Z")

</div>

@ cfajohnson:  
I'm having some errors with dir\_size? where can I find this function? Thanks in advance.

Best regards,

---

<div class="post-metadata">

**Author:** ![cfajohnson](https://community.unix.com/user_avatar/community.unix.com/cfajohnson/32/16669_2.png) [@cfajohnson](https://community.unix.com/u/cfajohnson)\
**Post date:** [September 4, 2009, 9:58am UTC](https://community.unix.com/t/split-folder-into-dvd-size/247839/8 "2009-09-04T09:58:55Z")

</div>

```nohighlight
dir_size() ## calculate total size of files in directory/ies
{
    for ds_dir
    do
      ls -l ${ds_dir:+${ds_dir%/}/} |
           grep -v '^d' |
           awk 'BEGIN {OFMT = "%d" } {total += $5} END { print total }'
    done
}

```
