Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to get colored output from the find command? That is, in the path of each found item, directories are blue, executable scripts are green, et cetera? I'm using version 4.4.2 of GNU findutils.

Edit - To clarify, each result would be highlighted like this:

  ^    ^  ^
  |    |  L green

(if, for example, executing find . -type f).

share|improve this question
I wrote a mostly-find-compatible replacement called bfs that has this functionality: github.com/tavianator/bfs – Tavian Barnes Jun 9 at 19:09
up vote 6 down vote accepted

UPDATE: I've added a new (different) script... Ignacio Vazquez-Abrams had a point: The question really asks for executable scripts are green, et cetera.. okay... you'll find such a (prototype) script at the end of this answer.

This first (original) section is about grc and grcat.

This should work; grc... (as enzotib has pointed out.. The package name is grc ... The sub-utility used in the example, is grcat

generic colouriser for everything

generic colouriser, can be used to colourise logfiles,
output of commands, arbitrary text....
configured via regexp's.

The following example prints

  • ./ in magenta
  • bin/cpp/ in cyan
  • bigint in bold white

I haven't fully sorted out how it handles it config file yet, but this looks like it will do what you want (once you tame it).. eg. for a file with no sub-dir, and the color sequence seems to not be in the same sequence as the expressions.
I assume it is possible (but I'm a bit busy at the moment)...

echo "# my config file
colours=bold white,magenta,cyan

find . -maxdepth 3 -name '*' | grcat findhi

Here is the new Ignacio inspired script :)

This works if you use a single path as the first arg to find.
There are UNTESTED issues in this script. It is only concept.
One issue is: Symbolic Links... murky waters...
As-is, it prints an ERROR when it encounters an unknown type (eg. a symbolic link), and then continues processing past that.
Thanks to enzotib for the tput examples.

dircol=$(tput bold ;tput setaf 4)
coloff=$(tput sgr0)

root="$HOME"       # define path here, not in 'find` arg
root="${root:-.}"  # default to '.'
root="${root%/}/"  # add trailing '/'
find "$root" -maxdepth 1 -name '*' -printf "%y %P\n" | 
  while read -r line ;do
    case $line in 
       d   ) printf "%s\n" "$dircol$root$coloff";;  
       d\ *) printf "%s\n" "$dircol$root${line:2}$coloff";;  
       f\ *) l="$root${line:2}"
             cd -P "$d" 
             printf "%s" "$dircol$d$coloff"  
             ls --color=always -R1 "$f"
             cd - >/dev/null
          *) printf "ERROR - type not yet catered for\n";;  
share|improve this answer
You forgot to say you are referring to the grcat utility from the grc package :) At the beginning I had some difficulties to understand what you're saying. – enzotib Dec 8 '11 at 9:29
I really missed the fact that the OP want a different color for different types of files. – enzotib Dec 8 '11 at 14:52

You could use -exec to do most of that (my solution doesn't color the directory part differently). If you have -print in your find command, replace it by -exec ls --color -d; if you're using the implicit printing, add that. This assumes your ls supports the --color option.

find . -exec ls --color -d {} \;
share|improve this answer
I'm not sure who upvoted this, but I don't believe they finished reading the question (not that I'm saying this answer deserves a corresponding downvote though)... – Ignacio Vazquez-Abrams Dec 8 '11 at 5:34

This does only the two-color highlight for path and filename, not the per-filetype thing of ls:

Configure the colors of grep output in the right way for matched and unmatched part, and match the filename:

$ export GREP_COLORS="sl=0;33;49:ms=1;34;49"
$ find /etc/ -type f | head | grep --color=always '^\|[^/]*$'


You may not want to overwrite the variable GREP_COLORS, so set it only for grep:

$ find /etc/ -type f | head | GREP_COLORS="sl=0;33;49:ms=1;34;49" grep --color=always '^\|[^/]*$'

(Definitions trom the deprecated variable GREP_COLOR have less priority than those in GREP_COLORS)

For the color codes, see colortest-16 from the package colortest,
and section "Set Graphics Rendition" in ANSI terminal command sequences.

share|improve this answer

I liked the -exec idea. I used it to create this function:

function ff {
    find . -name $1 -exec ls -G -d {} \;
share|improve this answer

Your Answer


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.