The command

find . -type l -not -xtype l -printf "%p -> %l\n"

prints all nonbroken symlinks under the directory .. I want to colorize this output so that the %p part is blue. I've tried

find . -type l -not -xtype l -printf '\e[1;34m%-6s\e[m' "%p -> %l\n"

but this results in the error find: warning: unrecognized escape \e. Any ideas how to fix this?

1 Answer 1


It is not quite correct, the color code sequence and the %p needs to be in the same argument to -printf and not in separate ones.

The -printf flag of find is different from the usual built-in from bash. The find version takes arguments of form -printf format while the built-in takes printf <FORMAT> <ARGUMENTS...>, which means the former doesn't accept format-specifiers followed by arguments but just a single string with options defined. The -printf option of find provides various sequences to describe the file attributes. The %s inside the find -printf conveys a different meaning than the format specification definition by the built-in.

Also I guess the printf from the find (GNU findutils) command only supports ANSI color codes and does not accept the \e escape sequences (unlike the built-in printf of the GNU shell, on the standalone GNU printf utility) but its octal equivalent only (here 033 assuming an ASCII-based system):

find . -type l -not -xtype l -printf '\033[1;34m%p\033[m -> %l\n'

You can add the ANSI color code of your choice to the above.

Or you can use the $'...' quoting operator found in a few shells including the GNU shell, which does recognise \e:

find . -type l -not -xtype l -printf $'\e[1;34m%p\e[m -> %l\n'

Above the \e and \n are expanded to the ESC and NL characters before being passed to find.

You must log in to answer this question.

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