PS | The grep app command does not show several ways to process the grep app itself
Using the PS command to query the process, often we do not want to print out "PS | grep app "This current process, such as the following:
-
[Root@localhost root]# ps-ef | grep java
-
Root 20070 20049 0 Nov19? xx:/usr/java/jdk1. 6. 0_07/bin/java
-
-dprogram.name=run.sh-server-xms512m-xmx1024m-xss128k-xx:+useparallelgc
-
-xx:+useparalleloldgc-xx:permsize=256m-xx:maxpermsize=512m
-
-dsun.rmi.dgc.client.gcinterval=3600000 -dsun.rmi.dgc.server.gcinterval=3600000
-
-djava.net.preferipv4st
-
Root 5523 5203 0 : pts/ 0 :xx : XX grep java
[Email protected] root]# Ps-ef | grep javaroot 20070 20049 0 Nov19? 00:24:33/USR/JAVA/JDK1.6.0_07/BIN/JAVA-DPROGRAM.NAME=RUN.SH-SERVER-XMS512M-XMX1024M-XSS128K-XX:+USEPARALLELGC- xx:+useparalleloldgc-xx:permsize=256m-xx:maxpermsize=512m-dsun.rmi.dgc.client.gcinterval=3600000- Dsun.rmi.dgc.server.gcinterval=3600000-djava.net.preferipv4stroot 5523 5203 0 10:49 pts/0 00:00:00 grep java
While the Java process is displayed, the "grep java" process will be printed out "root 5523 5203 0 10:49 pts/0 00:00:00 grep java", in order not to print this line, there are several ways, we look at which works well:
1.ps aux | grep java | Grep-v "grep"
2.ps aux|grep \[j]ava or PS aux|grep [J]ava
If you need to print out the process number, you can print it later with awk, as follows:
PS Aux|grep [J]ava | awk ' {print $} '
Ps-ef|grep Java|awk ' {if ($0~/run.sh/) print $} '
PS Aux|grep [J]ava | awk ' {if ($0~/run.sh/) print $ '
PS aux | grep java | Grep-v "grep" | awk ' {print $} '
PS aux | grep java | Grep-v "grep" | awk ' {print $} '
Ps-ef |grep oracle| awk ' {print $1,$7} '
And so on.
If you want to kill the current process, you can write it down, such as killing the Java process:
PS Aux|grep [J]ava | awk ' {print $} ' | Xargs kill-9
PS | The grep app command does not show several ways to process the grep app itself