====== ps でgrepについて ====== 新しい発見をしたのでメモ 今までは、ps でgrep を行う時に、grep自身を「grep -v grep」で省いてたが、一発で表示する方法 ===== 方法 ===== grepする文字の1文字目を[]で囲むことで、「grep -v grep」しなくてもgrep自身を省く事ができます。 # ps auxw | grep [h]ttp root 23531 0.0 1.1 256620 11448 ? Ss Jun11 0:02 /usr/sbin/httpd apache 30234 0.0 0.7 257644 7592 ? S 12:23 0:00 /usr/sbin/httpd apache 30557 0.0 0.7 257644 7624 ? S 12:36 0:00 /usr/sbin/httpd apache 31189 0.0 0.7 257644 7560 ? S 13:08 0:00 /usr/sbin/httpd apache 31665 0.0 0.7 257644 7500 ? S 13:32 0:00 /usr/sbin/httpd apache 31678 0.0 0.7 257644 7508 ? S 13:33 0:00 /usr/sbin/httpd apache 31702 0.0 0.7 257644 7404 ? S 13:35 0:00 /usr/sbin/httpd apache 31961 0.0 0.7 257644 8144 ? S 13:51 0:00 /usr/sbin/httpd apache 31962 0.0 0.7 257644 7488 ? S 13:51 0:00 /usr/sbin/httpd apache 31963 0.0 0.7 257644 7496 ? S 13:51 0:00 /usr/sbin/httpd apache 31965 0.0 0.7 257644 7500 ? S 13:51 0:00 /usr/sbin/httpd ===== 旧方法 ===== grep自身が表示されるので、正確なデータを取得する場合は、「grep -v grep」を入れる必要がある。 # ps auxw | grep http root 23531 0.0 1.1 256620 11448 ? Ss Jun11 0:02 /usr/sbin/httpd apache 30234 0.0 0.7 257644 7592 ? S 12:23 0:00 /usr/sbin/httpd apache 30557 0.0 0.7 257644 7624 ? S 12:36 0:00 /usr/sbin/httpd apache 31189 0.0 0.7 257644 7560 ? S 13:08 0:00 /usr/sbin/httpd apache 31665 0.0 0.7 257644 7512 ? S 13:32 0:00 /usr/sbin/httpd apache 31678 0.0 0.7 257644 7508 ? S 13:33 0:00 /usr/sbin/httpd apache 31702 0.0 0.7 257644 7404 ? S 13:35 0:00 /usr/sbin/httpd apache 31961 0.0 0.7 257644 8148 ? S 13:51 0:00 /usr/sbin/httpd apache 31962 0.0 0.7 257644 7504 ? S 13:51 0:00 /usr/sbin/httpd apache 31963 0.0 0.7 257644 7496 ? S 13:51 0:00 /usr/sbin/httpd apache 31965 0.0 0.7 257644 7500 ? S 13:51 0:00 /usr/sbin/httpd root 32167 0.0 0.0 65400 840 pts/0 S+ 14:00 0:00 grep http {{tag>Unixコマンド 標準}}