How to chown symbolic link – symlink

By default, if you try to chown symbolic link, e.g. symlink, it won’t work. User and group of symlink will stay the same after attempt. What you can do is add -h flag in your chown command. This flag stands for –no-dereference and it means »affect symbolic links instead of any referenced file«.

Example:

 
### symlink is owned by root
[root@myserver www]# ls -l
lrwxrwxrwx  1 root  root  13 May 14 14:51 html -> /var/www/html

### try to chown directory with nginx user and group
[root@myserver www]# chown nginx:nginx html

### no changes
[root@myserver www]# ls -l
lrwxrwxrwx  1 root  root  13 May 14 14:52 html -> /var/www/html

### try chown with -h flag
[root@myserver www]# chown -h nginx:nginx html

### ownership of symbolic link html is now changed
[root@myserver www]# ls -l
lrwxrwxrwx  1 nginx nginx 13 May 19 14:52 html -> /var/www/html

Got Something To Say:

Your email address will not be published. Required fields are marked *

*

I accept the Privacy Policy

This site uses Akismet to reduce spam. Learn how your comment data is processed.

© 2024 geegkytuts.net
Hosted by SIEL


About author