Sounds like a trick question. On several systems, you can change the permissions of symlinks with the fchmodat(2)
system call with the AT_SYMLINK_NOFOLLOW
flag or with a lchmod(2)
system call and with the chmod
command with the -h
option, but not on Linux-based OSes such as Ubuntu.
On many systems that allow changing those permissions, they are ignored anyway (macos being an exception IIRC), so there's little point changing them. In any case, I don't expect there'd be any system where the w
permission would be significant as symlinks cannot be modified (to change the target of a symlink, you need to recreate it with the new target for which you need write+search permission to the parent directory¹).
Here, you could cheat and redefine ls
as:
ls() (
set -o pipefail
command ls "$@" | sed 's/^lrwxrwxrwx/lrwxr-xr-x/'
)
(bearing in mind that as ls
's stdout is then a pipe, it might affect the formatting as most ls
implementations often give a different (more human friendly) output when it goes to a terminal device).
¹ That's own case where the ownership of the symlink may matter as if the t
(restricted deletion) bit is set on the directory and you don't own that directory, then you can delete the symlink unless you own it.