Split folder into dvd size

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,

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

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

Change the size in the variable bin_size.

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

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

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

Best regards,

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
}