Create rar without directory structure from command line

bashrar

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.

Best Answer

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