Change permissions for a symbolic link
I have a symlink with these permissions:
lrwxrwxrwx 1 myuser myuser 38 Aug 18 00:36 npm -> ../lib/node_modules/npm/bin/npm-cli.js*
The symlink is located in a .tar.gz archive. Now when I unpack the tar.gz archive using maven the symlink is no longer valid. I'm therefore trying to reconstruct the symlink. First I create the symlink using ln but how do I set the same permissions as the original symlink?
- 7 years ago
You can make a new symlink and move it to the location of the old link.
ln -s <new_location> npm2 mv -f npm2 npm
That will preserve the link ownership. Alternatively, you can use
chownto set the link's ownership manually.
chown -h myuser:myuser npm
On most systems, symlink permissions don't matter. When using the symlink, the permissions of the components of symlink's target will be checked. However, on some systems they do matter. MacOS requires read permission on the link for
readlink, and NetBSD's
sympermmount option forces link permissions checks on read and traversal. On those systems (and their relatives, including FreeBSD and OpenBSD) there is a equivalent
chmod -h 777 npm
I just ran into a permission problem with symlinks on a CentOS 6.8 server. The symlinks had owner:group of root:root. When the owner and group were changed to the user that owned the directory they were in, as shown in this answer, the permission problem went away.