List all active programs that starts with letter....

Nemesis

Member
Joined
Nov 19, 2019
Messages
31
Reaction score
5
Credits
46
Hi all!

I've been looking around to see if there is any way to list all active programs/services by only entering one or a few letters?

Something like:
ps -A pl*
And it would list all that starts with pl...
or:
ps -A *pl*
that list all that contains the letter pl?
This would be a lot easier to locate a program/service if you aren't sure exactly how it spells, or don't know the pid
 


JasKinasis

Well-Known Member
Joined
Apr 25, 2017
Messages
1,509
Reaction score
2,144
Credits
10,826
ps doesn't use any kind of pattern matching. It doesn't take any regex or globbing type arguments like that.

All it does is list a set of processes that belong to certain users, or everybody.

The arguments to ps just let you set whose processes to list
e.g.
all users, or a particular UID, or EUID

Or if you already know the PID of the process you want to view- you can specify it using the -p parameter

All of the other optional parameters to ps do things like:
Set which columns to display about each process in the output (UID, EUID, PID etc)

So if you're using ps and you want to do any kind of pattern matching based on the names of the processes - you will need to pipe the output from ps to something like grep, or ag (aka the silver searcher).
e.g.
using grep:
Bash:
ps -A | grep "pl*"

or using ag:
Bash:
ps -A | ag "pl*"

So you list ALL processes with ps and then filter the results using grep, or ag (if you have it installed).
 
Last edited:

JasKinasis

Well-Known Member
Joined
Apr 25, 2017
Messages
1,509
Reaction score
2,144
Credits
10,826
Another way to do it without using a pipe would be to use pgrep.
e.g.
Bash:
pgrep -l "pl*"

And that will list the PIDS and the names of any processes that match the pattern "pl*".

I would recommend taking a look at the man pages for pgrep and see all of the options available to you. pgrep is an extremely powerful tool for viewing information about processes.

But it depends on what information you want to see. So you could use either pgrep on it's own, or one of the ps | grep, or ps | ag combo's, as per my previous post.
 
OP
Nemesis

Nemesis

Member
Joined
Nov 19, 2019
Messages
31
Reaction score
5
Credits
46
Thanks for the tip, however, these commands list everything that contains a P, it's disregarding the following letter..
 

atanere

Well-Known Member
Joined
Apr 6, 2017
Messages
2,628
Reaction score
2,775
Credits
41
Thanks for the tip, however, these commands list everything that contains a P, it's disregarding the following letter..
Drop the (*) character. Just pgrep -l "pl" will narrow your search and use both letters of the search string. But the results are not necessarily at the beginning and can be anywhere in the output.

Cheers
 
OP
Nemesis

Nemesis

Member
Joined
Nov 19, 2019
Messages
31
Reaction score
5
Credits
46
pgrep -l "pl" showed 3 results, none of them was the wanted result.
ps -A | ag "pl" got 7, and 3 of them was the result i was searching for..

So thanks for the help!
 

JasKinasis

Well-Known Member
Joined
Apr 25, 2017
Messages
1,509
Reaction score
2,144
Credits
10,826
pgrep -l "pl" showed 3 results, none of them was the wanted result.
ps -A | ag "pl" got 7, and 3 of them was the result i was searching for..

So thanks for the help!

The trick to effectively using pattern matching programs like grep, ag and pgrep is to learn how to use regular expressions, aka regexes.

I used "pl*" in my example because it is what you used in your post. But the pattern "pl*" uses globbing, which is just a quick and dirty way to get results. To get more precise results - you'd need to construct a regex that better represents the pattern of characters you're looking for in the name. However, I didn't know which process/processes you were looking for - so I couldn't suggest anything better!
 
Last edited:
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Linux.org Hosting Donations
Consider making a donation

Members online

No members online now.

Top