1833914 Members
2131 Online
110063 Solutions
New Discussion

chown for symlinks

 
Chern Jian Leaw_1
Occasional Contributor

chown for symlinks

HI,
I have the directory below which is a sym-link:

lrwxrwxrwx 1 cleaw oper .... perl->../perl

I would like to change the ownership of both the link and also the source i.e ../perl. I had tried doing the following:

# chown -h root perl

but it changes only the ownership of the sym-link, and not that of the file/directory pointed to by the symlink.

#ls -l
lrwxrwxrwx 1 root oper .... perl->../perl

I executed chown as root.

Could someone tell me how I could also change the file/dir i.e ../perl pointed to by the symlink perl?

Thanks
7 REPLIES 7
Nick Wickens
Respected Contributor

Re: chown for symlinks

I think that the -h option may be your problem - Try it witout that option - see man page for chown.
Hats ? We don't need no stinkin' hats !!
Steve Steel
Honored Contributor

Re: chown for symlinks

Hi

From man chown

Options :chown and chgrp recognize the following options:

-h Change the owner or group of a symbolic link.

By default, the owner or group of the target file that a symbolic link points to is changed. With -h, the target file that the symbolic link points to is not affected. If the target file is a directory, and you specify -h and -R,recursion does not take place.

Thus you will never be able to do the two together.

steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
James R. Ferguson
Acclaimed Contributor

Re: chown for symlinks

Hi Chern:

'chown -h' does *not* affect the target file to which the symbolic link points. The man pages are quite clear on this.

Remember that neither the mode nor the ownership of a symbolic link matters. It is the mode and ownership of the file or directory to which the link points that's important.

Thus, if you want to change the ownership of your perl file, 'whown' the file, not the link.

If you want for cosmetic reasons to 'chown' both, use 'chown' with and without the '-h' option, appropriately.

Regards!

...JRF...
Chern Jian Leaw_1
Occasional Contributor

Re: chown for symlinks

Nick, Steve,

I tried chown as:
#chown root perl
chown:perl: A file or directory in the path name does not exists.

Any ideas on solving this error?

Thanks.
Pete Randall
Outstanding Contributor

Re: chown for symlinks

I think you need to do
"chown root ../perl"

Try that.

Pete

Pete
Wodisch
Honored Contributor

Re: chown for symlinks

Hi,

i addition you might want ot use the "-L" option to "ls", i.e. "ls -lL" to see the *real* (=working) permissions...

Just my $0.02,
Wodisch
Darrell Allen
Honored Contributor

Re: chown for symlinks

Hi,

Just wondering if you got your answer.

Assuming perl is a symlink pointing to ../perl

"chown -h root perl" will change the owner of the symlink "perl" to root

"chown root perl" will change the owner of the file "perl" points to (in this case "../perl") to root. It is effectively the same as doing "chown root ../perl".

If "chown root perl" says the file doesn't exist, it is referring to "../perl". Does ../perl actually exist?

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)