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.

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.

share|improve this question
add comment

1 Answer

up vote 10 down vote accepted

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
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.