2 min read

OS X Tools: All you really need to know about GREP

Originally published in: red66.com

Ever need to look through an endless file list to determine if a certain file is there? Cross-eyed from looking at a ps listing to find the one program you want to kill? You need grep.

And if you’re on a Mac (or a Unix/Linux machine) you’re in luck.

There’s a million ways to use grep, but this one will quickly show you how powerful it is (and it’s probably all you need to know).

Suppose you need to shutdown a particular program… one that doesn’t show up on the Activity Monitor. You open the Terminal application, type “ps -A” and watch in awe as a million lines shoot by your screen, trying to figure out which one corresponds to the program you wish to kill.

Instead, try this the next time:

Let’s pretend you need to shutdown a particular application that’s not responding (or doesn’t have a Quit option). I’ll use mozy as an example. Instead of going line-by-line looking for the one that includes mozy, you simply type this command:

ps -A | grep -i mozy

and you’ll get the following back:

24293 ?? Ss 0:03.52 /usr/sbin/MozyBackup

24449 p2 R+ 0:00.00 grep -i mozy

Now all you need to do is issue the following command:

sudo kill 24293

to shutdown the application.

What you’re doing is simply taking the result of the “ps -A” command and sending it, using the ”|” operator, to the grep utility, which will search for any occurrences of the phrase “mozy” (the -i option makes the search case insensitive).

Do you have any other uses for grep? Any other useful utilities? Leave your comment below.

Let's Connect

If you want to hire me or get in touch about something or just to say hi, reach out on social media or send me an email.

Other blogs

Some other blogs where I've posted throughout the years. Most of these will eventually migrate here.