0

I totally suck at Bash/Python/Ruby/Perl Scripting (need to practice/learn some more) so I'm asking for a little help :-)

I need to move about the contents of about 60 Maildirs to their parent folder and rename that parent folder too all on a Linux machine, of course I can use 'mv * .[^.]* ../' to do this, but its the repeating for multiple folders that I'd like to accomplish.

So currently I have /some/folder/prefix-user.name/Maildir/ and I want to end up with:

/some/folder/user.name/ which contains the contents of Maildir.

Two separate scripts would be fine, in fact it would probably be better so I have multiple examples to learn how to do this kind of repeated function automation :-)

Thank you for your help in advance!

1 Answer 1

1

I've been doing a lot of this sort of thing recently. (moving files in user folders that is!)

for u in $(ls -1 /some/folder/) do
  #give some feedback
  echo "Working on $u"
  # move the contents of Maildir up a level
  mv $u/Maildir/*.* $u
  #generate the new name for the user folder
  newname=$(echo $u | awk -F "-" '{print $2}')
  # move the user fodler to the new name
  mv $u $newname
done;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .