# chown command line argument not working



## bossa nova (Jun 3, 2003)

Can anyone tell me what is wrong with this argument. I keep getting a ton of errors.

the argument appears between the quotes "

here it is:
"find / -user 501 -exec chown admin { } \;"

not sure why it's not working.
tia...
john


----------



## Darkshadow (Jun 3, 2003)

Hmm...are you trying to change the ownership of the file or the group?  If you're trying to change the _group_ to admin, rather than to some user named admin, then change that to find / -user 501 -exec chgrp admin {} \; - you need to use chgrp in that case.

If you actually are trying to change the owner to a user named admin, try using admin's uid rather than name.


----------



## bossa nova (Jun 4, 2003)

actually I am trying to change it to another number burt what I am particularly interested in is the spaces and nomenclature.

I see that your brackets appear to have no space in the middle am I corrected? Perhaps this is where the error lies.


----------



## Darkshadow (Jun 4, 2003)

Hmm, actually, do it this way.

find / -user 501 -exec chown admin -- {} \;

That _--_ may be the problem.  I don't use find in this fashion very often, but all of the examples I've based my use of it off of have that _--_.  Really, though, I think that's just a safety catch (more or less).  That'll let the program know that whatever comes after that isn't commands any more.  That's just in case it comes across a file name that starts with a *-*.

Hmm, actually, on second thought, you probably _don't_ need that.  You have the user you want to change a file to separating the commands from the file name.  Probably won't hurt to try it, though.


----------



## Eckhart (Jun 4, 2003)

You're perfectly right: "--" is not the problem. Instead, you forget to put the brackets in quotes ("{}", no space needed), so depending on the shell you are using, they are interpreted by the shell rather than by find, causing problems:

find . -user paul -exec chgrp beatles "{}" \;

works fine. Just like:

find . -user 1002 -exec chgrp 666 "{}" \;

If the arguments in this case are numeric, both, find and chgrp interpret them properly as system ids.

Find sometimes seems to have a strange syntax and thus confuses, but actually not find but your shell requires these methods: "{}" or \; also -- at times.

Good luck again!


----------



## Eckhart (Jun 4, 2003)

You never learn enough about find  I just found out that if any spaces come between the brackets {}, the expression is then interpreted as a file name. This time by find and not your shell. Well, alright, that just by the way. Let me know if it works...


----------



## bossa nova (Jun 4, 2003)

Yes it worked without the spaces!

I went to an Apple presentation for macs in school labs and the guy who presented it gave out a sheet with tips. Basically by changing the user "admin" who is id 501 to id 499 using Netinfo, you are able to hide the admin accounts to the normal userrs. The login window hides id's lower then 500. So I used almost the same expression twice -once with "admin" and the second time changing 501 to 499.

There were some errors. He warned us there would be but said it would work fine. I tried it this morning and it works great. I can create an id for two admin groups and the clients do not see them. 

So it's a nice clean login window and less confusing.

So in the expression what is the first forward slash "/" representing or used for?


----------



## Darkshadow (Jun 5, 2003)

You mean the */* after find?  That's the directory you're telling find to search in.  In this case, */* stands for the "root" directory - that's the entire hard drive, _not_ anything related to the user root.

It's a handy thing - if you know what portion of your hard drive a file is in, you can search there instead of searching the entire drive by changing the */* to a different directory path.

If you'll notice, all POSIX paths start with that */* - that's because all directories stem from the root directory.  i.e. the path to your user admin would be /Users/admin - that translates to _directory admin of directory Users of the root directory_.


----------



## Eckhart (Jun 5, 2003)

Yes, sorry. "." (a single dot ) always means the CWD. ".." the directy above.

You'll see that in whatever directory you access on your filesystem. There are always these two entries. Of course, it's always better to use absolute pathnames.

The first argument to "find" is always the directory to look in...


----------

