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

jasonthat

macrumors newbie
Original poster
Oct 10, 2010
3
0
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.
 
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.

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

To give drw to the user:
Code:
chmod 0600 directory_path_here

The Unix environment variable for user is $USER.
 
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.

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

Code:
chown $USER: PathToFolder
 
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

Code:
chown $USER: PathToFolder


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.
 
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.

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

Code:
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.
 
Suppose a user logs in, opens Terminal (in Utilities) and enters

Code:
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.

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.