Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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:

~/stuff/01.d/01/files
~/stuff/02.d/files
~/stuff/03.d/files
~/stuff/04.d/lol/files
~/stuff/05.d/files

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
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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.