Trying to change the permissions of a symlink results in changing the permissions of its target

StackOverflow https://stackoverflow.com/questions/22627033

  •  20-06-2023
  •  | 
  •  

문제

I am trying to change the ownership of a symbolic link (jakarta) which points to another directory, but when I run

$ chown user1 jakarta

it changes the ownership of the directory that jakarta is pointing to instead. Why?

$ chown -h user1 jakarta
ownership of `jakarta' retained as user1
도움이 되었습니까?

해결책

You are attempting to change the ownership of a symbolic link, however, the permissions of the link itself don't matter - what mappers are the permissions of the target that the link points to. If you do, for whatever reason, want to change the ownership of the actual symlink you can use chown -h:

$ ll
total 4.0K
lrwxrwxrwx 1 root root    3 Mar 25 08:18 bar -> foo/
drwxrwxr-x 2 root root 4.0K Mar 25 08:18 foo/

$ chown -v quux:quux bar
changed ownership of `bar' from root:root to quux:quux

Note how it actually changed the target (foo):

$ ll
total 4.0K
lrwxrwxrwx 1 root root    3 Mar 25 08:18 bar -> foo/
drwxrwxr-x 2 quux quux 4.0K Mar 25 08:18 foo/

$ chown -vh quux:quux bar
changed ownership of `bar' from root:root to quux:quux

$ ll
total 4.0K
lrwxrwxrwx 1 quux quux    3 Mar 25 08:18 bar -> foo/
drwxrwxr-x 2 quux quux 4.0K Mar 25 08:18 foo/
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top