Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is there a way to control the color output of ls to highlight specific permissions on files? (e.g. write permissions).

enter image description here

Any options in LS_COLORS that would do this? (the image above is from Dired+ on Emacs 24.1, not from the output of ls)

share|improve this question
add comment

4 Answers

up vote 4 down vote accepted

You can always put ls on stereoids to achieve the coloring effect of file permissions.

share|improve this answer
add comment

If dircolors --print-database lists all possible options, there's no way to highlight permissions in long output.

You can still use grep:

ls -l | grep --color -P "(?<=[r-])w"

It will highlight all ws in the permissions part; it will also highlight ws following rs and -s in the file name, alas.

share|improve this answer
    
Looks great. I wonder if there is a way to update this so that it only matches the first hit on a white-space splitting of each line. Wouldn't that do the trick? –  user815423426 Sep 21 '12 at 2:11
add comment

I've just tried it, and this is actually possible with a little Ruby program called acoc (Arbitrary Command Output Colourer). It can be used to intercept output from any terminal program (colourised output in top and gcc is particularly neat) and colourise them according to a file of user-specified regular expression rules. It is a bit of work to set up, and you'll have to define your rules, but this is about as flexible as it gets. I was able to successfully add a rule to colourise world-writable files.

A couple of caveats to be aware of if you go down this route:

  1. This project doesn't seem to be in any distribution - you'll have to install manually from the homepage.
  2. You need to patch the code on the project homepage to work with modern versions of Ruby. You can find the patch here (I've contacted the author to let him know of the patch, perhaps he'll update his version).
  3. In the case of ls, intercepting with acoc throws away the existing LS_COLORS, so you'll have to provide all the rules you need as regular expressions, including things that used to be highlighted with LS_COLORS.
share|improve this answer
add comment

Don't know if this is what you are looking for. Some time ago I wrote a script that works as "ls" but shows some nice colors for permissions in the output. You can read about it here, download it here. I keep it in /usr/local/bin. If you're a debian|ubuntu based distro user, replace #!/bin/sh to #!/bin/bash in the script;) Ask, if you have questions.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.