How can I colorize hardlinks myself? Turns out on an old Ubuntu 10.04 I have, this happens by default (same .bashrc
and .profile
in use), whereas on the newer Ubuntu 12.04 it doesn't.
This is the output on Ubuntu 10.04 (the one I desire):
And this is the output on Ubuntu 12.04:
The relevant file is .vimrc
, however, .viminfo
is an ordinary file with link count 1, in contrast to the hardlinked .vimrc
.
Of course the fact that GNU coreutils
uses texinfo pages instead of man pages doesn't make things easier. I found this here, but it doesn't refer to the case I am looking for.
TL;DR: how to achieve coloring hardlinked (as in: link count > 1) files the way I like in various Ubuntu versions.
Do this:
And you may edit your
~/.profile
to changeLS_COLORS
accordingly.Background
This feature was enabled as default in 2008 has been disabled by default in 2009. Somehow the freeze for Ubuntu 10.04 was exactly in between those moments.
Using the Git repository of coreutils I see that the commit to revert automatic colourization has been in since version 7.5:
In versions before 7.1 there seems no upstream maintained support for this:
The source file
multihardlink.sh
, lead me to the exactLS_COLORS
value to enable it again.You may want to reopen LP Bug #123423.
Based on gertvdijk's answer, I came up with the following snippet, which suits my needs:
Edit: I actually had to rewrite the snippet (see edit history).
Turns out that
ls
swallows the error output concerningLS_COLORS
when piping it. At least I couldn'tgrep
for it, neither with2>&1
nor without. Hence the changes. We check fordircolors
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 forhl=
ormh=
respectively in the output ofdircolors
. This way we can detect which is expected byls
andexport LS_COLORS
accordingly. It may be safer togrep
for:hl=
and:mh=
respectively to rule out the possibility for file extensions ending inhl
ormh
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.