chown is not changing symbolic link
356,154
Solution 1
I was putting a slash in the end of target:
chown -h myuser:mygroup mysymbolic/
just removed the slash in the end and works. Here's the correct way:
chown -h myuser:mygroup mysymbolic
Solution 2
I've tried this myself and it works for me. If you have the -h it changes the owner of the symbolic link, but if you dont then it changes the owner of the file itself and not the link.
But it doesnt seem to work of the symbolic link is linked to a directory
Solution 3
I was unable to chown
a directory even with -h
but using the full path worked.
# ls -al
drwxr-xr-x 2 deploy deploy 4096 Dec 30 10:29 .
drwxr-xr-x 3 deploy deploy 4096 Dec 30 08:59 ..
lrwxrwxrwx 1 root root 32 Dec 30 09:02 apps -> /u/apps/
# chown -h deploy:deploy apps
# ls -al
drwxr-xr-x 2 deploy deploy 4096 Dec 30 10:29 .
drwxr-xr-x 3 deploy deploy 4096 Dec 30 08:59 ..
lrwxrwxrwx 1 root root 32 Dec 30 09:02 apps -> /u/apps/
# chown -h deploy:deploy apps/
# ls -al
drwxr-xr-x 2 deploy deploy 4096 Dec 30 10:29 .
drwxr-xr-x 3 deploy deploy 4096 Dec 30 08:59 ..
lrwxrwxrwx 1 root root 32 Dec 30 09:02 apps -> /u/apps/
# pwd
/var/www/html
# chown -h deploy:deploy /var/www/html/apps
# ls -al
drwxr-xr-x 2 deploy deploy 4096 Dec 30 10:29 .
drwxr-xr-x 3 deploy deploy 4096 Dec 30 08:59 ..
lrwxrwxrwx 1 deploy deploy 32 Dec 30 09:02 apps -> /u/apps/
Solution 4
Is the target a file or a directory?
If it is a directory then try -H (upper case H)
Solution 5
simply.
chown -h myuser:mygroup <symlink> [without trailing slash]
should be enough and work!
Related videos on Youtube
Author by
Admin
Updated on September 17, 2022Comments
-
Admin over 1 year
I'm trying to change the user/group of a symbolic link with the command:
$ chown -h myuser:mygroup mysymbolic/
But it's not changing. I'm logged in as root. The current user/group is set to root:root. What went wrong?
-
Jichao over 14 yearsWhich operating system do you use?Acoording to the manaul page,-h option takes affect only on systems that can change the ownership of symbolic link.
-
Ortomala Lokni over 7 yearsAre you on a NFS mount?
-
David Schwartz over 6 yearsAnything that ends with
/
is a directory. You meanmysymbolic
, which is the symbolic link, notmysymbolic/
which is probably the directory it points to.
-
-
Admin over 14 yearsthe target is a directory
-
Admin over 14 yearssee my edited reply about directory
-
Admin almost 14 yearsSorry for the thread necromancy, but I'd like to point out that the correct syntax is with the lowercase 'h'.
-
Radek over 13 yearsdoesn't work for me on ubuntu
-
defines about 13 yearsWow, this took me hours to find.
-
IQAndreas almost 11 years@Radek It worked for me on Ubuntu so long as I remembered the
-h
flag. -
friederbluemle over 10 yearsWorks for me on Ubuntu with
-h
and without the trailing slash. -
Matijs almost 10 yearsFor what it's worth, the man page on OS X is a lot clearer on the -h option than the one on (Arch) Linux. “-h If the file is a symbolic link, change the user ID and/or the group ID of the link itself.” vs. “-h, --no-dereference affect symbolic links instead of any referenced file (useful only on systems that can change the ownership of a symlink)”
-
zigojacko about 9 yearsThank goodness you found out what the reason was! Cheers
-
Antony D'Andrea about 9 yearsHad the same problem but wasn't putting the slash. Turns out that -h arguement is very important!
-
Antony D'Andrea almost 9 yearsI can't believe after 4 years, I have bumped into my past self suffereing the same problem, the missin '-h'!
-
pepoluan about 8 years@AntonyD'Andrea well, you're certainly older ... :-P
-
Layne Bernardo almost 4 yearsIf you chown a symlink like that it actually affects the referenced files. If you want to change the symlink itself you need to use the switch
-h
, or –no-dereference