Joe Zeff wrote:
> On 7/18/26 12:44 PM, Bob Marčan via users wrote:
>> Is this a competition in using a command alias or solving
>> a problem with a clear, all-understandable command?
>
> In my case, it's an easy way to find a program's PID, if
> you want to look at it or kill it.  The reason for the
> second grep is left as an exercise for the reader.

I'd argue that pgrep is a better way to solve that task.
With -af it outputs the PID and full command line, similar
to what you'd get from ps aux.  It has options to limit the
matches based on numerous other criteria, e.g.: user, group,
run state, etc.).

It's also handy because you can largely just run it again
switching pgrep to pkill to kill the command (removing the
-a option, which is only relevant to pgrep).

More generally for grep tasks where you don't want to match
grep (process output and shell history are two common places
where that's often the case), you can avoid the second pipe
to grep by using something like 'grep [f]oo' (that is
placing a single character in the string in a bracket
expression).

Not that most people need to care about an additional process
(and if they do, using shell at all isn't going to be
ideal), but it is good to know.  It saves a little typing
and makes scripts and command lines ever-so-slightly easier
to read.

Other than muscle memory for those who learned long before
pgrep was common, 'ps … | grep … | grep -v grep' is not the
ideal way to solve this problem anymore. :)

-- 
Todd

Attachment: signature.asc
Description: PGP signature

-- 
_______________________________________________
users mailing list -- [email protected]
To unsubscribe send an email to [email protected]
Fedora Code of Conduct: 
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/[email protected]
Do not reply to spam, report it: 
https://forge.fedoraproject.org/infra/tickets/issues/new

Reply via email to