LoginSignup
0
0

More than 3 years have passed since last update.

grep時にgrepが出ないようにgrepする

Posted at

プロセス確認時に任意の文字列を含んだプロセスを抽出するとき

ps aux | grep target

とすると

mochimochi 18277  248  1.4 1122692 367144 ?      Sl   21:18   0:39 ./target_process
mochimochi 18294  231  1.5 1253764 373160 ?      Sl   21:18   0:34 ./target_process
root     18565  0.0  0.0 112828   972 pts/0    S+   21:19   0:00 grep --color=auto target

コマンド叩いた自分自身もリスト化されるのが微妙に邪魔
なのでvオプション(除外)を使用する

ps aux | grep target | grep -v grep

目的の文字列を含みつつgrep除外対象としてgrepを指定する

mochimochi 18277  248  1.4 1122692 367144 ?      Sl   21:18   0:39 ./target_process
mochimochi 18294  231  1.5 1253764 373160 ?      Sl   21:18   0:34 ./target_process
0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0