LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-25-2008, 10:28 PM   #1
leftty
Member
 
Registered: Aug 2008
Location: austin, tx
Distribution: Slackware64
Posts: 35

Rep: Reputation: 15
color support for less or most


Hello. Does anyone know how to keep colored text when viewing files through less or most? Thanks.
 
Old 08-25-2008, 10:41 PM   #2
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
The terminal emulator must support, and be set for, color.

What terminal type are you using ?

echo $TERM
 
Old 08-26-2008, 10:22 AM   #3
leftty
Member
 
Registered: Aug 2008
Location: austin, tx
Distribution: Slackware64
Posts: 35

Original Poster
Rep: Reputation: 15
echo $TERM
linux

I did say "keep" color, which implies that my bash terminal uses color except with the less program.
 
Old 08-26-2008, 11:47 AM   #4
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
I see. There is no shortage of poorly worded questions in the forums, and it is not always easy to pull the relavant facts from sloppy language.

Less and more do not have syntax highlighting, so the best color you will get with them is two color (foreground/background) plus any standard attributes such as bold, underline, blink, etc.
 
Old 08-26-2008, 02:18 PM   #5
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
Try the -R option to less.
 
Old 08-26-2008, 02:22 PM   #6
arizonagroovejet
Senior Member
 
Registered: Jun 2005
Location: England
Distribution: openSUSE, Fedora, CentOS
Posts: 1,094

Rep: Reputation: 198Reputation: 198
Depending on exactly what you want to do you may find the -r option on less useful. Try these commands

Code:
$ (echo -e "\E[1;34m";ls) | less
$ (echo -e "\E[1;34m";ls) | less -r
and note how in the first one the first line of what less displays is "ESC[1;34m" but in the second command that line is missing and all the text is blue. I used this recently where I wanted to have some coloured output in something that would be displayed by less. E.g. this is a very crude and convoluted example of colouring the output of ls when it's display with less

Code:
$ foo=`for i in *;do if  test -d "$i";then echo  "\E[1;34m" ;fi; ls -lhd  "$i";echo  "\E[0m\n"; done` && echo -e $foo | less -r
 
Old 08-29-2008, 02:59 AM   #7
leftty
Member
 
Registered: Aug 2008
Location: austin, tx
Distribution: Slackware64
Posts: 35

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Mr. C. View Post
I see. There is no shortage of poorly worded questions in the forums, and it is not always easy to pull the relavant facts from sloppy language.
"Relevant" is misspelled. And thanks to arizonagroovejet.

Last edited by leftty; 08-29-2008 at 03:02 AM.
 
Old 08-29-2008, 03:22 AM   #8
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
And so is leftty. Find more interesting things to say.
 
Old 10-24-2014, 02:02 PM   #9
FcoJavier99
LQ Newbie
 
Registered: Oct 2014
Posts: 1

Rep: Reputation: Disabled
Try this

ls -R /bin --color=always | less -r
ls -R /bin /etc | sort | uniq | grep --color=always sh | less -r

the keys are:
  • -r option for less.
  • and --color=always option for the other one.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
REQ: Gimp plugin fo automatic color correction and color masks Rick069 Linux - Software 1 04-15-2007 04:10 PM
Does Linux support 32bit color scanning? dejavu_01 Linux - Newbie 9 07-12-2006 10:32 AM
multiple color support in aterm ????? UsualTuxpect Linux - Software 6 08-27-2004 10:14 AM
[COLOR=red]ENCORE WIRELESS PCI Card 802.11b [/COLOR] enrique145 Linux - Hardware 3 07-07-2004 03:31 PM
[COLOR=seagreen]HELP-want to use Kickstart/rh7.2 on a notebook[/COLOR] verbali Linux - Newbie 1 05-13-2002 02:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration