0

I recently found an example of colored output when using ls:

enter image description here

AFAIK that is on MacOS with the BSD implementation of ls.

I know how I can change the color of the filenames via LS_COLOR, but I would like to color e.g. the permissions.

I could think of a combination of sed, ANSI escape codes and printing the output back to stdout, but that feels very heavy.

Has anyone an idea on how to accomplish that task with GNU ls?

3
  • Are you sure that your shell is bash? (I know that a few years ago Mac switched to zsh as the default shell.)
    – dg99
    Apr 19, 2022 at 3:05
  • @dg99 I use zsh on most systems, but I would prefer to find a solution which works for bash as well, as I use bash on a few of my machines. Apr 19, 2022 at 3:08
  • 1
    The shell is irrelevant, this is all down to whatever program is listing the files. Apr 19, 2022 at 7:43

1 Answer 1

1

You can’t do this with GNU ls, short of either post-processing the output (as you mention) or making the appropriate changes in the source code and building your own version.

The output you show looks like it came from exa, not BSD ls (other than the colours, the absence of the group information suggests exa). You can install this on Linux too; that would probably be the simplest way of reproducing this type of output on your system.

2
  • It's also interesting that the screenshot shows an l command, not ls
    – Jeff Schaller
    Apr 19, 2022 at 13:17
  • Thanks, using exa is the more sane alternative to writing a wrapper script which adds the coloring. @JeffSchaller l would be an alias to ls + arguments if I recall correctly. I for example have the alias l='ls -laht' defined. Apr 19, 2022 at 21:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .