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 there any sane way to highlight the 4th, 5th, and 6th columns from the right of the file size in ls -l? My intention is to make it easy to read a file size be it in bytes, KiBs, or MiBs. I do know about the -h flag, but I find that having to interpret the letters at the end is more cumbersome than just looking and seeing the length of the number (magnitude). This is the same reason why race cars use analogue dials instead of digital.

My target shell is Bash. Thanks.

EDIT: I am looking to highlight the thousands, ten thousands, and one hundred thousands places of the size column. Like this: 123456789

share|improve this question
Maybe this can help you out: unix.stackexchange.com/a/49270/14084 – Bernhard Nov 29 '12 at 14:14
Thanks, Bernhard! I do use your solution to that question every day, I have lsl aliased to it with some minor changes. In fact, the answer to this question will be combined with your technique there in my lsl alias. – dotancohen Nov 29 '12 at 15:45
@dotancohen Ah, didn't realize it was the same guy asking the question, but I was actually referring to this ls++ answer here :) – Bernhard Nov 29 '12 at 16:19
I see. ls++ doesn't address this issue, unfortunately. – dotancohen Nov 29 '12 at 18:25
@Bernhard: It still needs some tweaking, but take a look: grep --color -E -- "$(ls -rtl $@ | tail -n4)|$" <(ls -l $@ | perl -pe 's{^((?:\S+\s+){4}\d*)(\d{3})(?=\d{3})}{$1\e[31;1m$2\e[m}') – dotancohen Nov 29 '12 at 18:33
up vote 6 down vote accepted

Maybe something like:

ls -l | perl -pe 'BEGIN{@color=(0,2,3,1,5,4)}
  s{((?:\S+\s+){4})(\d+)}{"$1\e[3" . 
  $color[log($2||1)/log(2)/10] . "m$2\e[m"}e'

For black (or whatever the default foreground colour is on your terminal) for sizes from 0 to 1023, green from 1k to 1M, yellow for 1M to 1G, then red, purple, blue.

Edit. Based on your edited requirements:

ls -l | perl -pe 's{^((?:\S+\s+){4}\d*)(\d{3})(?=\d{3})}
share|improve this answer
Cool! I presume one would want to have an alias for that though? :) – posdef Nov 29 '12 at 14:33
Thanks. It is not what I'm looking for (I'll clarify the question) but it is certainly helpful and I just learned a bunch of perl from it! – dotancohen Nov 29 '12 at 15:38
Very nice! And thank you for teaching me some perl! – dotancohen Nov 29 '12 at 18:32

The easiest way withou installing any additional software is to grep --color whatever you want. To highlight filesize from ls output you should run something like that (sometimes it will highlight not only size):

ls -l | grep --color '\s\+[0-9]\+\s'

Othwerwise please refer to the similar question on SO.

share|improve this answer
Thank you. In fact, highlighting the number is not what I am looking for. I have clarified the question. In any case, +1 due to teaching me something new! – dotancohen Nov 29 '12 at 15:43

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.