PDA

View Full Version : [ubuntu] Creating rar files of a certain size



echris1
May 7th, 2008, 09:04 AM
When you right click on a file you want to archive and click on Create Archive, you can select rar, but is there any way to get more specific? I'd like to get a rar thats 100MB and uses only minimal compression, because there it's only video, and thats compressed enough anyway. I know the command line to do this is:



rar a -v100000 filname.rar filename.avi


or at least thats how to divide it up, I'm not sure how to specify compression.

Is there a way to make a script or something that I can put in the menu next to create archive? Or at least a way to have those options in the gui?

Thanks,
echris1

Xiong Chiamiov
May 7th, 2008, 09:18 AM
For Dolphin and Konqueror, I know you can create service menus, but I know nothing about GNOME. That said, why again do you not want to compress it fully? I don't think it's quite possible to do what you're asking except possibly by having a script that compresses using several different levels and finds the one closest using a binary search or something, but that's completely inefficient for whatever it is you're trying to do.

echris1
May 7th, 2008, 09:28 AM
It's not that I don't want to compress it fully, I just want to store it, break it up into 100MB sized rar files. The compression doesn't matter at all. I guess I'm really just wondering how to add things to the right click menu.

vanadium
May 7th, 2008, 10:15 AM
You might need a proprietary version of rar to create multi-volume archives of a preset size. Even then, no version for Linux might be available.

I would stick with free software. Because video is highly compressed, I would not attempt to compress furhter (will hardly work) but directly split the file in 100 Mb chunks using the "split" tool, which is by default present on your system. See "man split" for how it works.

subzero316
May 7th, 2008, 10:33 AM
rar a -v10000k archive.rar <files>

thats about 100 mb files

echris1
May 7th, 2008, 09:34 PM
Thanks subzero, I left out the k, but I was wondering if it's possible to add that command to the right click menu, so if I were to right click on a video file or something, I would see an option to compress into 100MB chunks. Is there a way to put something in that menu to launch a console and execute that command?

Monicker
May 7th, 2008, 10:13 PM
Thanks subzero, I left out the k, but I was wondering if it's possible to add that command to the right click menu, so if I were to right click on a video file or something, I would see an option to compress into 100MB chunks. Is there a way to put something in that menu to launch a console and execute that command?

Install the nautilus-actions package. After it is installed:

System -> Preferences -> Nautilus Actions Configuration -> Add

Label - SplitRarFile
Tooltip - Create split rar archive from file
Icon - just pick one you like

Take the following and save it in your home dir as splitrar.sh


#!/bin/bash

for file in "$*"
do

rar a -v10000k archive.rar $file

done

Right click saved file -> Properties -> Permissions -> Allow Executing File as program

Use path to file in Nautilus configuration

Path - /home/username/splitrar.sh
Parameter - %m

Save the action. ALT + F2, killall nautilus. After that when you right click on a file you should have a menu item called SplitRarFile. Selecting that action will now run the script and create the split rar files in the directory.

echris1
May 8th, 2008, 02:06 AM
I have it all setup, and the menu item shows up, but when I select it nothing happens. No extra processes start running and no terminals pop up. Is there something I'm missing somewhere?

Monicker
May 8th, 2008, 02:38 AM
Did you make sure the splitrar.sh file is executable? You might go over all the settings again. It worked fine when I tested it on my computer.

echris1
May 8th, 2008, 02:55 AM
It is set to be executable, still nothing happening. The nautilus action setup looks like this:

http://content.imagesocket.com/images/splitrarfilecba.jpg

and the splitrar.sh looks like this:



#!/bin/bash

for file in "$*"
do

rar a -v10000k archive.rar $file

done


I was wondering if it is also possible to change archive.rar to $file.rar?

Monicker
May 8th, 2008, 03:14 AM
You can change it to $file.rar if you like.


I just tested on my system again, and I think I found the problem. I bet the file you were trying to rar had spaces or other characters in it. I tend to forget about that. :P

Use this for the script:


#!/bin/bash

for file in "$*"
do

rar a -v10000k "$file.rar" "$file"

done

glennric
May 8th, 2008, 03:26 AM
Change the script to be


#!/bin/bash

IFS="
"

for file in "$*"
do

rar a -v10000k "$file.rar" "$file"

done
and then the spaces in file names won't be a problem anymore.

echris1
May 8th, 2008, 03:31 AM
Tried both of those scripts, still nothing happening when I try to do it. Does it matter at all if it's on an NTFS drive? I mean, the regular command works fine when I just type it in. Do I need to set permissions or something other than the run as executable?

Monicker
May 8th, 2008, 03:37 AM
I wouldn't think ntfs would matter,especially if you can do it manually, but I suppose its possible. I don't have any ntfs partitions to test that out though.

kakao
August 10th, 2008, 09:44 PM
Change the script to be


#!/bin/bash

IFS="
"

for file in "$*"
do

rar a -v10000k "$file.rar" "$file"

done

Haven't tried it, just thinking about it, but shouldn't it rather be something like



#!/bin/bash

IFS="
"
rar a -v10000k "archive.rar" "$*"


This way I'd expect to get one file containing all selected files/folders rather that one file each for every selection I made in nautilus...

Cheers.