Skip navigation
This discussion is archived

Folder Creation and Permissions

2858 Views 13 Replies Latest reply: Nov 30, 2009 8:43 AM by Antonio Rocco RSS
Antonio Rocco Level 6 Level 6 (10,095 points)
Currently Being Moderated
Nov 28, 2009 3:25 PM
Hi

I've created a plain text file that has a list of names each on a separate line all lower case and no space. I'm using:

for i in `cat /Users/home/Desktop/list.txt`; do mkdir $i; done

which creates appropriate folders based on the names in the list. How can I change the owner permission of each folder to be owner based on the name of the created folder? For example if I issue:

for i in `cat /Users/tony/Desktop/batch/list.txt`; do chown -R:Staff $i; done

The command completes with no errors but no change is made. When I try using chmod instead or in conjunction with chown I either get 'invalid argument' errors or again no change.

Any assistance gratefully received.

Tony
  • etresoft Level 7 Level 7 (23,880 points)
    Currently Being Moderated
    Nov 28, 2009 4:43 PM (in response to Antonio Rocco)
    You need a space between "-R" and "staff", which should be all lowercase.
    MacBook 2007 (white), Mac OS X (10.6.2), 2.0 Ghz/4GB Ram/200 HD
  • BobHarris Level 6 Level 6 (12,495 points)
    Currently Being Moderated
    Nov 28, 2009 6:20 PM (in response to Antonio Rocco)
    for i in `cat /Users/tony/Desktop/batch/list.txt`; do chown -R:Staff $i; done

    If you are not a member of the target group, you will need sudo and if you are trying to change the owner, rather than the group, you would also need to use sudo

    while read newdir
    do
    mkdir -p "$newdir"
    sudo chown -R :staff "$newdir"
    done </Users/tony/Desktop/batch/list.txt

    You will be prompted at least once for your password (this also assumes you are part of the admin group).

    The "..." around $newdir, protects it from any spaces in the directory names.

    The *while read* loop is more flexible, and does not get upset about spaces that may be in filenames.

    And you have already been told about a space between the -R and the :staff
    Mac OS X (10.5.8), MacBook, PowerMac G5, Mac mini, iPod Touch, iBook G4, MacBook Pro, iMac G4
  • hungryjoe Level 2 Level 2 (250 points)
    Currently Being Moderated
    Nov 29, 2009 10:38 AM (in response to Antonio Rocco)
    If you are changing the group of the files why not just use the chgrp command?
    MacBook Pro, Mac OS X (10.6.2)
  • Andbrowny Level 4 Level 4 (1,610 points)
    Currently Being Moderated
    Nov 29, 2009 1:17 PM (in response to Antonio Rocco)
    Hi Tony, what about

    while read newdir
    do
    mkdir -p "$newdir"
    sudo chown -R "$newdir" "$newdir"
    done </Users/tony/Desktop/batch/list.txt


    Cheers
    iMac ; MacBook ; MacBook Pro ; Mac Pro ; XServe ;, Mac OS X (10.5.6), OSX Server ; .local AD ; WINXP/Vista via Parallels Mac OS X 10.5.x/10.4.x
  • Andbrowny Level 4 Level 4 (1,610 points)
    Currently Being Moderated
    Nov 29, 2009 1:58 PM (in response to Antonio Rocco)
    Hi again Tony, I suspect the problem is that they aren't in the local directory, do these accounts exist? AFAIK, OSX can't chown something to someone who doesn't exist.

    Cheers
    iMac ; MacBook ; MacBook Pro ; Mac Pro ; XServe ;, Mac OS X (10.5.6), OSX Server ; .local AD ; WINXP/Vista via Parallels Mac OS X 10.5.x/10.4.x
  • BobHarris Level 6 Level 6 (12,495 points)
    Currently Being Moderated
    Nov 29, 2009 4:24 PM (in response to Antonio Rocco)
    Do you want to change the owner to 'staff' ?

    if that is the case, then do not use the : before 'staff'
    Mac OS X (10.5.8), MacBook, PowerMac G5, Mac mini, iPod Touch, iBook G4, MacBook Pro, iMac G4
  • etresoft Level 7 Level 7 (23,880 points)
    Currently Being Moderated
    Nov 29, 2009 4:32 PM (in response to Antonio Rocco)
    Antonio Rocco wrote:
    The group's not a problem. I want to change the owner.


    OK,
    Let's take a step back here. Just what kind of problem are you experiencing with these files that makes you want to change the owner?
    MacBook 2007 (white), Mac OS X (10.6.2), 2.0 Ghz/4GB Ram/200 HD

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.