chown symbolic link
Posted by danielDec 28
One of the most commonly used Linux system administration tools is chown, which is part of the coreutils package. It is used to change the user and/or group ownership of a given file or directory. Something to be aware of this tool is, it doesn’t change the ownership of symbolic links, as shown below –
root@linubuvma:/tmp# touch test root@linubuvma:/tmp# ls -l test -rw-r--r-- 1 root root 12 Dec 20 08:01 test root@linubuvma:/tmp# ln -s test sltest root@linubuvma:/tmp# ls -l sltest lrwxrwxrwx 1 root root 4 Dec 20 08:01 sltest -> test root@linubuvma:/tmp# chown daniel:daniel sltest root@linubuvma:/tmp# ls -l sltest lrwxrwxrwx 1 root root 4 Dec 20 08:01 sltest -> test
The reason this doesn’t work is in the man page for chown – symbolic links named by arguments are silently left unchanged unless -h is used.” By simply running chown on symbolic link without ‘-h’ option, you are changing the ownership of the target. The ‘-h’ option affects symbolic links instead of any referenced file.
root@linubuvma:/tmp# chown -h daniel:daniel sltest root@linubuvma:/tmp# ls -l sltest lrwxrwxrwx 1 daniel daniel 4 Dec 20 08:01 sltest -> test
Though not portable, in some distros
chown -R
will recursively change the owernship of all files, including symbolic link files and directories. In my case, ‘chown -R /path/to/file’ works for GNU chown which is part of the ‘GNU coreutils 8.21’ package on Ubuntu 14.04.
No comments
You must be logged in to post a comment.