10

I know, I can specify custom time format for ls like this

ls -lAF --time-style="+ %Y-%b-%d  %H:%M:%S" --color=always

but I would like to "smuggle in" colors inside the time format. For example, I would like to have the year 2014 in red color. How would I do that?

I have tried putting the color code \033[0;31m in front of the %Y, but the code does not get interpreted as color but as gibberish.

0

1 Answer 1

13

Enter the ESC character literally. This is usually done by entering Ctrl+V and then the requested key, in this case Esc.

Or in ksh93, zsh or bash, use the $'...' quotes where echo-like escape sequences are expanded:

ls -lAF --time-style=$'+ \e[31m%Y\e[m-%b-%d  %H:%M:%S' --color=always

You must log in to answer this question.

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