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.


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").

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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