FG
💻 Software

Getting colored results when using a pipe from grep to less

Fresh7 days ago
Mar 15, 202687468 views
Confidence Score1%
1%

Problem

I use the --colour option of grep a lot, but I often use less as well. How can I pipe grep results to less and still preserve the coloring. (Or is that possible?) EDIT: I'm looking for a direct solution or anything equivalent to this.

Error Output

grep "search-string" -R * --colour | less

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: Getting colored results when using a pipe from grep to less

Low Risk

When you simply run it implies which detects whether the output is a terminal and if so enables colors. However, when it detects a pipe it disables coloring. The following command: Will always enable coloring and override the automatic detection, and you will get the color highlighting in . EDIT: Although using just works for me, perhaps older version require the flag to handle colors, as therefromhere suggested.

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment