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've got a folder full of folders, and some of those folders may or may not have folders in them. It looks something like this:


I want to make separate .rars for each of the folders in ~/stuff, so I was going to do for f in *.d; do rar a "${f//.d/.rar}" "$f"; done which worked great, and gave me the rars. But I'd rather have no directory structure in the rars at all, just files. Is there an easy way to do this? It seemed like one of the switches looked like it might have done what I wanted, but the man page is a bit confusing. I'll try a few things.

I may end up trying to figure out a bash script to cd into the directory, check if it's the files, if so make the .rar in the parent (../${f//.d/.rar}), else go into the directory again and make the rar two parents up (../../${f//.d/.rar}). In this case, I'd want rar a ../"${f//.d/.rar}" * I think, I haven't tested it.

share|improve this question
up vote 2 down vote accepted

I think you want the -ep switch:

for f in *.d; do rar a -ep "${f//.d/.rar}" "$f"; done

That will give you a rar for each directory, with no directory structure within them ("ep" = "exclude paths from names").

share|improve this answer
This is exactly what I wanted, I missed it completely in the man page. – Rob Nov 17 '11 at 23:31

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.