LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-25-2005, 09:53 AM   #1
dr_zayus69
Member
 
Registered: Sep 2004
Location: western massachusetts
Distribution: fedora core 3, Suse 10
Posts: 877

Rep: Reputation: 35
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.

Last edited by dr_zayus69; 06-25-2005 at 09:59 AM.
 
Old 06-25-2005, 01:15 PM   #2
ahh
Member
 
Registered: May 2004
Location: UK
Distribution: Gentoo
Posts: 293

Rep: Reputation: 31
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.
 
Old 06-25-2005, 02:03 PM   #3
dr_zayus69
Member
 
Registered: Sep 2004
Location: western massachusetts
Distribution: fedora core 3, Suse 10
Posts: 877

Original Poster
Rep: Reputation: 35
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
 
Old 06-25-2005, 02:33 PM   #4
ahh
Member
 
Registered: May 2004
Location: UK
Distribution: Gentoo
Posts: 293

Rep: Reputation: 31
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.
 
Old 06-27-2005, 12:53 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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.
 
Old 06-27-2005, 01:20 AM   #6
puffinman
Member
 
Registered: Jan 2005
Location: Atlanta, GA
Distribution: Gentoo, Slackware
Posts: 217

Rep: Reputation: 31
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.
 
Old 06-27-2005, 03:12 AM   #7
enemorales
Member
 
Registered: Jul 2004
Location: Santiago, Chile
Distribution: Ubuntu
Posts: 410

Rep: Reputation: 31
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.

Last edited by enemorales; 06-27-2005 at 03:13 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linker option or utility to split out size of .o files e2vincent Linux - General 1 04-15-2005 01:50 AM
A simple command displaying the size of a directory satimis Linux - Newbie 5 11-24-2004 12:06 AM
Apache piped logs - split-logfile - zero size files alex_fittyfives Linux - Enterprise 0 08-26-2004 07:04 AM
Directory contains 26,000 files. How to split into sub-dirs? BrianK Linux - General 4 05-12-2004 04:37 PM
redhat command to display the size of directory please! sandrinechen Linux - Newbie 4 04-19-2004 03:19 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration