Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need a script to rar my files

usage will be like this

r1 archivename fileordirtocompress

with following attributes

rar a -m0 -v1024000 -r 

How whould this bash script look like?


for file in "$*"

rar a -v10000k archive.rar $file


I found something like that but I wish I could change the archive name


r1 MyPhotos Myphotos/ = MyPhotos.rar (Myphotos/ inside with subfolders)

r1 Nicemusic *.mp3 = Nicemusic.rar (all .mp3 inside)

r1 Familyvideo movie1.avi = Familyvideo (movie1.avi file inside)

share|improve this question
up vote 1 down vote accepted

You can use the variable $file to name the archive as well.


for file in "$*"

    rar a -m0 -v1024000 -r ${file}.rar $file


Note that I changed the options to rar to what you said you wanted. The for loop stores every file it finds in * (i.e. every file in the current directory) in the variable $file, one by one, as it goes through the loop. You need the {} around the name of the variable before .rar to make sure bash doesn't think you're trying to find a variable called $file.rar.

share|improve this answer
It's not working with folders with space r1 Phot My/ Photo\ giving: WARNING: No files – John Oct 28 '13 at 8:04
Try enclosing the $file in quotes, like so: "$file" – darthbith Oct 28 '13 at 12:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.