Based on gertvdijk's answer, I came up with the following snippet, which suits my needs:
if [[ -e "/etc/debian_version" ]] && type dircolors > /dev/null 2>&1; then
command dircolors|command grep -q 'hl=' && export LS_COLORS="ln=01;36:hl=00;36"
command dircolors|command grep -q 'mh=' && export LS_COLORS="ln=01;36:mh=00;36"
Edit: I actually had to rewrite the snippet (see edit history).
Turns out that
ls swallows the error output concerning
LS_COLORS when piping it. At least I couldn't
grep for it, neither with
2>&1 nor without. Hence the changes. We check for
dircolors to be available. If it is, it's expected to output a snippet of shell code (Bourne shell compatible by default) that contains the defaults for the various recognized file types. So we check for
mh= respectively in the output of
dircolors. This way we can detect which is expected by
export LS_COLORS accordingly. It may be safer to
:mh= respectively to rule out the possibility for file extensions ending in
mh and matching our condition.
The above colors are light cyan on black for soft links and a darker cyan on default black for hard links.
You can vary the top-level condition, of course. I am currently only setting it on Debian/Ubuntu, because I have no time to test it on older RHEL/CentOS systems at the moment.
NB: the invocations via
command are to work around potential aliases/functions with the same names as the tools we try to use here.