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

Say I wanted to copy the .ssh/authorized_keys file in each user's /home directory to /tmp (for whatever reason). I figured I could use globbing and brace expansion to do this quickly, but I ran into trouble. I tried using something like key_for_{*} to get a different file name for each user. My thought was that I could copy everything like this,

sudo cp */.ssh/authorized_keys /tmp/key_for_{*}

I expected /tmp to have files like /tmp/key_for_alice, /tmp/key_for_james, &c... but that's not what happened.

Googling about I found plenty of examples of brace expansion but none that addressed this question. Is there something I should know?


share|improve this question
up vote 3 down vote accepted

That's not brace expansion. That's just... an asterisk inside braces. You'll need to use a for loop for this.

for user in *
  cp "$user"/.ssh/authorized_keys /tmp/key_for_"$user"
share|improve this answer
ha ha ha OK thanks! – Ziggy Jul 4 '11 at 20:43

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.