[20170828]grep過濾技巧.txt--//經常使用grep過濾顯示信息.# ps -ef |grep oraagentoracle 13416 1 0 2016 ? 1-20:48:04 /u01/app/11.2.0.4/grid/bin/oraagent.bingrid 17423 1 ...
[20170828]grep過濾技巧.txt
--//經常使用grep過濾顯示信息.
# ps -ef |grep oraagent
oracle 13416 1 0 2016 ? 1-20:48:04 /u01/app/11.2.0.4/grid/bin/oraagent.bin
grid 17423 1 0 2014 ? 2-03:32:14 /u01/app/11.2.0.4/grid/bin/oraagent.bin
grid 21718 1 0 2014 ? 1-16:45:43 /u01/app/11.2.0.4/grid/bin/oraagent.bin
root 87599 66070 0 09:38 pts/0 00:00:00 grep oraagent
--//這樣有一個小小的遺憾,把執行grep oraagent信息也帶了出來,許多人常用的方法是
# ps -ef |grep oraagent | grep -v grep
oracle 13416 1 0 2016 ? 1-20:48:05 /u01/app/11.2.0.4/grid/bin/oraagent.bin
grid 17423 1 0 2014 ? 2-03:32:15 /u01/app/11.2.0.4/grid/bin/oraagent.bin
grid 21718 1 0 2014 ? 1-16:45:43 /u01/app/11.2.0.4/grid/bin/oraagent.bin
--//實際上解決很簡單.修改執行如下:
# ps -ef |grep oraagen[t]
oracle 13416 1 0 2016 ? 1-20:48:04 /u01/app/11.2.0.4/grid/bin/oraagent.bin
grid 17423 1 0 2014 ? 2-03:32:15 /u01/app/11.2.0.4/grid/bin/oraagent.bin
grid 21718 1 0 2014 ? 1-16:45:43 /u01/app/11.2.0.4/grid/bin/oraagent.bin
--//實際grep過濾顯示信息還是oraagent.而這樣grep 命令的執行是grep oraagen[t].這樣不滿足過濾條件oraagent,就能顯示需要的信
--//息.
--//以下別人問的問題,加入想顯示ps -ef 的頭.一般改用egrep.
# ps -ef |egrep "oraagent|UI[D]"
UID PID PPID C STIME TTY TIME CMD
oracle 13416 1 0 2016 ? 1-20:48:08 /u01/app/11.2.0.4/grid/bin/oraagent.bin
grid 17423 1 0 2014 ? 2-03:32:16 /u01/app/11.2.0.4/grid/bin/oraagent.bin
grid 21718 1 0 2014 ? 1-16:45:45 /u01/app/11.2.0.4/grid/bin/oraagent.bin
root 111809 66070 0 09:51 pts/0 00:00:00 egrep oraagent|UI[D]
--//但是這樣這樣又把egrep oraagent|UI[D]給帶了出來.實際上如果你定義grep相關環境變數,看看顯示的顏色就明白問題在那裡了.
# env | grep -i grep_
GREP_COLOR=01;32
GREP_OPTIONS=--color=auto
--//這樣在顯示上oraagent顯示綠色.修改如下:
# ps -ef |egrep "oraagen[t]|UI[D]"
UID PID PPID C STIME TTY TIME CMD
oracle 13416 1 0 2016 ? 1-20:48:09 /u01/app/11.2.0.4/grid/bin/oraagent.bin
grid 17423 1 0 2014 ? 2-03:32:17 /u01/app/11.2.0.4/grid/bin/oraagent.bin
grid 21718 1 0 2014 ? 1-16:45:45 /u01/app/11.2.0.4/grid/bin/oraagent.bin
--//這樣就ok了,也許還有許多方法可以做到!^_^.`