changing ownership

getpwuid() works fine but is there a way to get a users uid not just the logged in user because what im trying to do is have this go through a directory and change owners folder by folder because a server was copied over but now admin owns the files, not the user so what i need it to do is basically get the uid from the short name store it in a variable and pass it to chown.
 
by anychance is there a grep like function in c, what ive done is made it so it out puts to a file like this

username:uid:gid

for all users on the machine so there is a point of refrence for the program, but it would be much easier if i could grep a line and then have the code parse it store the uid and gid in different variables and pass it to chown.
 
Is there any particular reason why you're making a new program to do this?

You can use the chown command in the command line to recursively go through a folder and change the owner of all of its contents.

command would look like: sudo chown -R UID:GID /path/to/folder.

(You can leave out the GID if you're not changing that)

Just be sure to pick the right folder, or you can really mess up OS X's permissions. ;)
 
Many programs don't need the overhead of forking another process just to alter ownership.

However, I just read your purpose which I had missed a few posts ago, and chmod -R is indeed the way to go. You can use either UID:GID or username:groupname to specify an owner.
 
i would do it manually from the command line but the thing is that there are some 700 users who need ownership changed and id rather be able to do it in an automated way.
 
It would be in your best interest, then, to learn about shell scripting. Here's an example, for bash, which should do what you need:

Code:
#!/bin/bash
for i in `ls /Users`
do
chown -R $i /Users/$i
done

Stick that in a file, chmod +x it, and run it.
 
You'd have to sudo run that shell script - only the root user (or sudo) can do the chown command.

Just thought I'd let you know ;)
 
Back
Top