Grep: RRTFM

 in

If you've been a Linix/UNIX user for a long time you surely know what RTFM means (Read The *bleep* Manual). I'd like to offer up a new, related acronym, RRTFM, for Re-Read The *bleep* Manual.

My first exposure to *NIX was decades ago and just recently somebody pointed out some new options to grep that I've found very useful since then (more about those below). Now, if I'd re-read the man page during the last few years these wouldn't have been so new to me and the richness that it's brought to my life would have been extended by years.

Specifically, the new grep options that I've found to be quite useful are:

  • -P or --perl-regexp makes grep interpret the pattern you pass as a perl compatible regular expression (PCRE). PCREs are often much more convenient, and often more powerful, than grep regular expressions.
  • --color causes the matched text to be colorized on output. This is particularily useful when you're grepping files with long lines, it makes the match stand out.

    Note: Normally grep doesn't colorize when its output is going to a pipe, so if you're piping the output into more or less you want to do --color=always to get the colorization.
  • -o or --only-matching causes the matched text and only the matched text to be output, all other text in the line is not displayed.
  • -r, -R or --recursive causes directories to be recursed and the files within them to be searched. By itself this turns out not to be as useful as you'd like, you probabaly need to use the --include and --exclude options to specify the files to be searched.

We all know that the rate of change is rapid, and that goes for the old standbys that we use everyday, so it pays to re-read the man/info pages now and then to check for new and useful features. If you don't like that option, then talk to new users. The person that pointed this out to me is fairly new to Linux and so their first reading of the manual was much more recent than mine.

______________________

Mitch Frazier is an Associate Editor for Linux Journal.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

How needs colors on greps output

vinylmeister's picture

Monochrome displays are fine with Linux, if you want to look for colors, use vista :-)

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState