Force apt(8) to generate color through pipe

aptcolorspipe

Output from apt listis often tens of thousands line long, so I usually run instead

apt list | less # or another program

but there's no color in this way. Can I retain the color while piping apt(8)'s output?

  • This one has already failed:

    sudo apt install expect
    unbuffer apt list | less
    

    unbuffer converts all invisible characters to visible counterparts.

  • From man apt, I also tried this:

    apt -o APT:Color=true list | less
    

    apt says "Configuration item specification must have an =<var>" but I don't know the correct value for <val>.

Best Answer

OK, I found the fault.

Actually the control character conversion is not done by unbuffer(1), but less(1) itself. So the answer is simple: stick to unbuffer and give an option to less to tell it to stop converting Escapes.

unbuffer apt list | less -R
Related Question