Command line - Changing permissions with chown

Discussion in 'Mac Basics and Help' started by jasonthat, Oct 10, 2010.

  1. jasonthat macrumors newbie

    Oct 10, 2010
    This has got to be an easy one for the command line experts. Could someone please tell me how to run the chown utility, so as to change permissions of a folder to read & write for the "currently logged in user"? I guess I am looking for a variable for the username, since I will be running this command as part of a shell script. I do not wish to specify a username, which would make it possible for me to run the script on any computer for any logged in user.
    Thanks in advance.
  2. Nermal Moderator


    Staff Member

    Dec 7, 2002
    New Zealand
    I don't know the exact command offhand, but I think you want chmod instead of chown.
  3. robbieduncan Moderator emeritus


    Jul 24, 2002
    chown doesn't change permissions. It changes ownership (change owner). Look at chmod instead.
  4. mac2x macrumors 65816

    Sep 19, 2009
    As the two posters above intimated, you want chmod rather than chown.

    To give drw to the user:
    chmod 0600 directory_path_here
    The Unix environment variable for user is $USER.
  5. LPZ macrumors 65816

    Jul 11, 2006
    So there's some folder (where is it in the file system?) and its permissions are read and write for the owner and no access for group and others? And you simply want to change the owner of the folder (when? when the user logs in?) Do you need to restore ownership to the previous owner when the current user departs? What about ownership of the files in the folder? Who is running the script?

    Perhaps it would help if you told us what you're trying to do and why. That said, you might use

    chown $USER: PathToFolder
  6. jasonthat thread starter macrumors newbie

    Oct 10, 2010

    The files for which the permissions need to be changed are under /Users/Shared/"files to be changed"
    The command needs to run as part of a script, which would be saved on the user's dock. The script when run should have the permissions for these files changed to Read & Write for the currently logged in user (located under /Users/Shared/*.*) which are created by another third-party software. At the time of user login, these files will only have Read-only permission for loggedinuser, Wheel and everyone.

    The command that I was trying was:
    do shell script "chown loggedinuser /Users/Shared/*.*"

    I tried the command you suggested - although it does not give any errors while running, it does not change permissions for the loggedinuser.

    *this user will have administrator privileges on the local computer
    *not required to restore to the previous owner when current user departs.
  7. LPZ macrumors 65816

    Jul 11, 2006
    Suppose a user logs in, opens Terminal (in Utilities) and enters

    cd /Users/Shared; ls -l *.*
    Please post what output he sees. I'm trying to understand who owns the files in question, and what group the files belong to. At this point I tend to agree with earlier posters who suggest that you want chmod not chown. But I'm still unclear about what you want.
  8. jasonthat thread starter macrumors newbie

    Oct 10, 2010
    I would just confuse other thread readers if I try to explain deep on my situation. At the moment, all I need is to change permissions on two files with *.aspx extension under the /Users/Shared folder, which gets created the first time the software is opened.

    I know this command works smoothly if I run it manually through the terminal:

    sudo chown loggedinuser /Users/Shared/*.aspx

    But now I am trying to run it as part of the script, where I would like to know how instead of specifying the username, what variable can be put in there for any currently logged in user? The $USER: variable does not seem to work.
  9. LPZ macrumors 65816

    Jul 11, 2006
    sudo chown $USER: /Users/Shared/*.aspx

Share This Page