14

On my linux machine, you can tell intact symlinks from broken ones, because broken ones are colored red. I've tried to set this up on my mac by adding some configurations to PSCOLORS in my .bash_profile, but so far nothing has worked. I've managed to get the coloring to tell apart directories, files, executables, and symlinks. However, the broken symlinks are not a different color than intact symlinks. Searching around on google hasn't rendered any promising results. Ideas? Tricks?

JW8
  • 1,192
  • 3
  • 12
  • 26
well actually
  • 533
  • 4
  • 8
  • 12
  • 1
    You might be successful in installing a port of Linux' `ls` that supports coloring symbolic links for their targets, and colors orphaned links. OS X's `ls` simply cannot do it. It's [150KB of source code](http://ftp.gnu.org/gnu/coreutils/) vs. [25KB of source code](http://opensource.apple.com/source/file_cmds/file_cmds-212.1/ls/)... – Daniel Beck May 18 '12 at 09:41

2 Answers2

12

Install Homebrew first.

  1. Install GNU coreutils: brew install coreutils
  2. Put the following in your ~/.bash_profile: eval $(gdircolors) alias ls="gls --color=auto"

Open a new shell, and broken links will be highlighted like on Linux.

Fish Monitor
  • 430
  • 5
  • 9
  • 1
    don't forget to add the following alias in your ~/.bash_profile: `alias ls="gls --color=auto"` – carlodef Oct 31 '14 at 14:43
  • 1
    As it is just an output of `dircolors`, you can as well just put `eval $(dircolors)` in your `~/.bash_profile` (if dircolors is installed) – Scz Nov 11 '16 at 10:27
  • Nice tips, I've added it to the answer. Thanks to @lorenzo. – Fish Monitor Nov 20 '16 at 02:35
7

I don't think it's possible – the man page for ls doesn't list a color slot for broken symlinks.

Here's a handy find one-liner for finding broken symlinks:

find -L . -type l -ls
slhck
  • 223,558
  • 70
  • 607
  • 592
Tom
  • 86
  • 1
  • 2