How to create the same folder inside 200 other folders?

Discussion in 'macOS' started by docprego, Apr 5, 2015.

  1. docprego macrumors 65816

    Joined:
    Jun 12, 2007
    Location:
    Henderson, NV
    #1
    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
     
  2. pmau macrumors 65816

    Joined:
    Nov 9, 2010
    #2
    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
     
  3. docprego thread starter macrumors 65816

    Joined:
    Jun 12, 2007
    Location:
    Henderson, NV
    #3
    Thank you!

    I would like to try this tomorrow but don't understand how to use it. Could you please give a quick explanation?
     
  4. docprego thread starter macrumors 65816

    Joined:
    Jun 12, 2007
    Location:
    Henderson, NV
    #4
    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.
     
  5. Mcmeowmers macrumors 6502

    Joined:
    Jun 1, 2015
    #5
    Make a shared folder that all the users can read from but not write to.
     
  6. docprego, Feb 8, 2016
    Last edited: Feb 9, 2016

    docprego thread starter macrumors 65816

    Joined:
    Jun 12, 2007
    Location:
    Henderson, NV
    #6
    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.
     
  7. ScoobyMcDoo, Feb 9, 2016
    Last edited: Feb 9, 2016

    ScoobyMcDoo macrumors 65816

    Joined:
    Nov 26, 2007
    Location:
    Austin, TX
    #7
    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.
     

Share This Page