grep

Use zgrep to grep a gzip (gz) file

Linux zgrep FAQ: How do I use the Linux zgrep command? (Or, How do I grep a GZ file?)

Linux users quickly learn how to use the Linux grep command on plain text files, but it takes a little longer to really you can grep gzip (gz) files as well. Here's how.

Linux ‘find’ command error: missing argument to -exec

Problem: I just issued a Linux find command, and got the following error message:

find: missing argument to -exec

Solution: Amazingly, it turns out that the computer is right, and I messed up my command. I entered my find command like this:

grep reverse: how to reverse the meaning of a `grep` search

Problem

You need to reverse the meaning of a search you're performing with the grep command. For instance, you've been searching for pepperoni pizza orders like this:

grep pepperoni pizza-orders.txt

and now you need to find all orders that don't have pepperoni.

Solution

Just add the -v switch to your grep search command, like this:

Linux gzip: How to work with compressed files

If you work much with Unix and Linux systems you'll eventually run into the terrific file compression utilities, gzip and gunzip. As their names imply, the first command creates compressed files (by gzip'ing them), and the second command unzip's those files.

In this tutorial I take a quick look at the gzip and gunzip file compression utilities, along with their companion tools you may not have known about: zcat, zgrep, and zmore.

How to search a Perl list for a pattern using grep

A lot of times when you're using Perl you have a list (or array), and you need to search that list for all strings that match a certain regular expression pattern (or regex). Fortunately Perl is built for this type of work, and it's straightforward to (a) perform this search, and (b) put your search results in another list.

Linux grep command man page

The contents of this page come from the CentOS Linux grep man page, i.e., the man page for the Linux grep command (also known as the help page for the grep command).

Finding files that Spotlight is missing

I generally use Spotlight when searching my Mac for a file, but there are times it doesn't work, especially when I'm trying to find a file that contains a phrase I know. For instance, I may have a file named "Fred.txt", and it contains the phrase "foo bar", but when I open Spotlight and type in "foo bar", the file Fred.txt never shows up.

More Linux grep command examples

The Linux grep command is used to search for text. The name "grep" means something like "general regular expression parser", and if you look at the grep man page it says "print lines matching a pattern". I always tell people that if they don't like the name "grep" they can think of it as "search" instead.

In "grep tutorial", we'll share a number of grep example commands. Let's get started.

Linux file searching: Search for text in files with find and grep commands

Linux find/grep FAQ: How can I combine the Linux find and grep commands to search a large collection of files?

A lot of times when I need to find a file I know the text in the file that I'm looking for, but I can't remember the filename, or can't think of what directory it might be in, other than somewhere below my home directory. When this happens, and other search means like the "locate" command don't help, my favorite way of searching for text strings in files that are spread through a bunch of directories and sub-directories is this: