
Colorize Files in Your Pager #15
Chapter 2, Console
|
49
HACK
The Black-and-White Problem
Now here’s the problem that might plague you at times. You want to view a
list of files, so you issue the command
ls –a. That command lists all the regu-
lar and hidden files, and all the files and directories appear in living color. Or
perhaps you prefer to use the command
ls –al that lists all regular and hidden
files in a detailed single column. Once again, the files appear in living color.
When there are many files, the list scrolls off the screen. This is particularly
troublesome on a text console that doesn’t let you scroll back far enough to
see the beginning of the list. What’s a geek to do? The intuitive solution is to
issue this command:
$ ls –al | less
This pipes the output of ls –al through the less pager, which lets you scroll
back and forth through the entire output of the
ls –al command.
There’s just one catch. All the pretty colors are gone. It is no longer easy to
identify compressed files from executable files (and so on…) at a glance.
You don’t see colors in the less pager for two reasons. First, less requires the
–R command-line switch to display colors. That won’t be enough for most
Linux users, however. You can find out for yourself if adding the –
R switch
is all you need for your Linux distribution by typing this command:
$ ls –al | less -R
Did you see the list of files in color? Probably not. ...