Group Symlinks with Directories in ls Output and Differentiate Them

directorylssymlink

In ls output, I'd like to group symlinks that point to directories along with the rest of the directories, but still have a way of telling that it's a symlink either with color or an appended symbol. Is there a way to do this?

If a symlink points to a directory, you can tell in output from ls by using the -F, --classify argument and by setting LINK target in the dircolors. Then it will be shown as dir_link@, but with the same color as a directory.

The ls command can group directories together with the --group-directories-first option.

The only way I can see to group symlinks to directories along with other directories is to use the -L, --dereference option. But this changes both the appended indicator as well as the color of the entry (even if you set links to be displayed as their own color independent of the target); it's then indistinguishable from a regular directory.

I'm using GNU ls on Linux.

Best Answer

The LS_COLORS variable has an option for symbolic links. The LN option, if given a unique color compared to the DI option, will show all symbolic links as that color instead.

See http://linux-sxs.org/housekeeping/lscolors.html for basic options. There is ways of setting individual extension types to their own colors, so there may be a way to set symbolic link directories a different color than symbolic link files, but that takes playing around.