I’m trying to make a server manager, but I need to grab the process IDs and Commands of some processes.
For example:
ps ax | grep ./skulltag
4760 pts/2 Tl 0:02 ./skulltag-server
4793 pts/2 Tl 0:01 ./skulltag-server
4956 pts/2 Tl 0:01 ./skulltag-server -port 13000
4958 pts/2 Tl 0:26 ./skulltag-server -port 13001
How would I get it to only return the process, only return the command (./skulltag-server) or both? Thanks.
You can pipe to awk to select which field to output
E.g.
ps ax | grep ./skulltag | awk '{ print $1 }'will print the first column (pid)Note that you may also want to look into using the -o option to ps to modify its output