Skip to content

*nix command of the day

2006 October 23
by bcp

I’m taking a few days of training this week for a specific suite of products. During class today I learned about a really simple command: pgrep. It lets you grep through running processes based on numerous attributes. For years I’ve always done something like ps auxww | grep foo when all I really needed was pgrep foo. Why didn’t anyone ever enlighten me? Think of how many fewer characters I could have typed in my lifetime …

No, it’s not earth-shattering, and it’s not like I was using cat file.txt | wc -l rather than wc -l file.txt. (Now that would be embarrassing.) Still, it’s refreshing every now and then to learn simpler ways to do things.

3 Responses leave one →
  1. October 24, 2006

    You’re the one that taught me ps auxww | grep foo, and now you’ve taught me the replacement.

    I don’t know if I ever realized how significant you were in my computing life. You essentially taught me how to use Linux and vim.

    Thanks man.

  2. October 24, 2006

    pgrep is quite nifty. If you use -fl you get a nice long format.

    Along the same lines are you familiar with pkill? This would, for example, allow you to do a pkill syslog instead of doing something like pgrep syslog & kill $PID or a kill `pgrep syslog`

    When I’m feeling particularly verbose I will do a cat file.txt | wc -l, but I do know better. :-)

  3. October 24, 2006

    Topherone, I’m glad I still have the opportunity to “clarify” things I’ve passed along in the past under the guise of being helpful. :-P It warms my heart to know I helped steer someone away from nastiness and toward a true text editor. (I don’t have anything against emacs. It’s just fun to taunt people.) Seriously, though, thanks for the comments, Topher.

    And Jay, I did find pkill moments after pgrep, as the man page for pgrep referenced it. I then went out to find what other p* commands I might not know about. The most interesting one was pinky, a lightweight version of finger. Not particularly useful, but it amused me.

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS