Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

docprego

macrumors 65816
Original poster
Jun 12, 2007
1,244
111
Henderson, NV
I have 200 users accessing my OS X server with access only to their user name and password protected folder. Often I need to place an identically named empty folder in all 200 of their user folders. I have not found a way to automate this and consequently am stuck copying it and then pasting it individually into their folders. It's quicker than you might think, but a major nuisance.

Is there any way I can automate this chore?

Thank you
 
Don't run this it's only an example:

If all Users are in /Users, a shell loop might look like this.

Code:
cd /Users || exit 1
for user in bob mike alice joe ; do
  mkdir $user/NewFolder
  chown $user $user/NewFolder
done

This assumes
1) You are root
2) All user home directories are located under "/Users"
3) The users' directory name is equivalent to their account short name
4) You have to replace "NewFolder" with the folder you want to create
 
Thank you!

I would like to try this tomorrow but don't understand how to use it. Could you please give a quick explanation?
 
Bringing this thread back from the dead. I never could figure out what pmau suggested and I never heard from him again.

I'm still trying to figure out how I can create a folder and then copy it to 200 other folders. Any suggestions would be appreciated.

Thank you.
 
Make a shared folder that all the users can read from but not write to.
Thank you for the suggestion. However I must have an identical folder inside each user's folder. I just can't figure out a way to automate this.

For example I have users numbered 1-160 each having their own folder. I'd like to place a folder named "sample" inside each of these 160 folders without having to manually copy and paste it in each.
 
Last edited:
Bringing this thread back from the dead. I never could figure out what pmau suggested and I never heard from him again.

I'm still trying to figure out how I can create a folder and then copy it to 200 other folders. Any suggestions would be appreciated.

Thank you.

That is a bash script. Put the contents of pmau's message into a text file. Then open Terminal, make the file executable by typing:

chmod +x <filename>

Then execute the file by typing:

./<filename>

Of course replace <filename> with whatever you named the script.

Now, if you want to add this folder to every user that has a directory in /Users, you could save yourself the time of typing all the usernames by changing the for loop to something like:

for user in $( ls ) ; do

Also it would probably be to your benefit to learn how to script. Here is a guide on different bash scripting tutorials out there.
 
Last edited:
  • Like
Reactions: Mcmeowmers
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.