LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   command to split up directory by size? (https://www.linuxquestions.org/questions/programming-9/command-to-split-up-directory-by-size-337039/)

dr_zayus69 06-25-2005 09:53 AM

command to split up directory by size?
 
here is the situation: i have a music folder that is a little over two gigs. I need to split it up into folders of about 700 mb cuz im backing it up on cds because im doing a fresh install and don't want to rip my cds again. Is there a command that would let me copy or move them into folders according to size limits that i could automate thru a shell script? Also i would like the directory tree structure to remain as intact as possible - it is broken up into folders like /artist/album/files so i wouldn't want it to just mix up the files into one directory. I could do it manually but i imagine such a script would be useful in mutliple situations. Any replies are appreciated, thanks in advance.

ahh 06-25-2005 01:15 PM

To be honest I don't think a shell script is your best bet.

This is how I would do it:-
1) Open konqueror.
2) In your home dir make three new folders, cd1, cd2 & cd3
3) Press Ctl+Shift+L
4) Press Ctl+Shift+T
5) Press Ctl+Shift+T

You should now have four panes open, one on the left and three on the right.

6) Click in the left pane and navigate to your music dir
7) Click in the top right pane and navigate to cd1 dir
8) Click in the middle right pane and navigate to cd2 dir
9) Click in the bottom right pane and navigate to cd3 dir
10) You can now drag and drop your music between these directories. The task bar at the bottom of each pane will tell you how many MB each is using.

dr_zayus69 06-25-2005 02:03 PM

im using gnome so my browser for the filesystem is nautilis so the ctrl+shift+ t or l doesn't work. I assume i may be able to do it in nautilis as well but i don't know the key combos for nautilis to give the same affect

ahh 06-25-2005 02:33 PM

I use Gnome too, but I still use Konqueror for my file manager - just a personal preference.

I'm afraid you will have to have to right click on the directories you want and choose "open in new window". You can then drag and drop between the windows. If you resize the windows to fit on your desktop it wont be a lot different.

chrism01 06-27-2005 12:53 AM

One possible soln would be to create 26 dirs one for each letter of the alphabet, then copy (recursively) the dirs by artist into the appropriate new dirs.
This would be fairly easy to do in eg Bash.

puffinman 06-27-2005 01:20 AM

Use du -s to get the sizes of each folder and break them up into 700 meg chunks. Something like this...

Code:

#!/usr/bin/perl

$srcdir = "$ENV{HOME}/mymuzak";
$destdir = "$ENV{HOME}/mybackups";
$destprefix = "music";
$limit = 700_000_000; # 700 megs

mkdir $destdir if not -e $destdir;

@albums = `du -s $srcdir/*`;
chomp foreach @albums;

# set total above limit so it will go to
# the else clause on the first iteration,
# incrementing $current_dir and creating it
$current_dir = 0;
$total = $limit+1;

foreach (@albums) {
  ($size,$name) = split /\s+/, $_;
  if (($size + $total) < $limit) {
    `cp -R $name $destdir/$destprefix$current_dir`;
    $total += $size;
  } else {
    die "$name is bigger than $limit" if $size > $limit;
    $current_dir++;
    mkdir "$destdir/$destprefix$current_dir";
    `cp -R $name $destdir/$destprefix$current_dir`;
    $total = $size;
  }
}

And since you're going to just burn anyway, you could symlink instead of copy and make sure your burning software follows the symlinks. In that case you'd use ln -s instead of cp -R.

enemorales 06-27-2005 03:12 AM

Hi,

You can also use tar and split to backup your music (and actually all your files). Now:

- You won't be able to listen to the music from the CDs :(
- You already have the music in CDs (you said you only want to avoid to rip them again):)
- It will keep your directory structure :)
- It could be optimum in space (doesn't leave unused bytes in the CDs) :)

So the balance is possitive...

PS: Only one thing. I haven't used split, so TEST FIRST.


All times are GMT -5. The time now is 09:55 AM.