17.18. Filtrowanie wyniku polecenia ps za pomocą instrukcji grep, ale z pominięciem w zestawieniu samej instrukcji grep
Problem
Chcemy przefiltrować listing wynikowy polecenia ps
za pomocą instrukcji grep
, ale nie chcemy, aby na tej liście był uwzględniony sam proces grep
.
Rozwiązanie
Należy zmienić wzorzec dopasowania w taki sposób, aby był poprawnym wyrażeniem regularnym, ale jednocześnie nie odpowiadał rzeczywistemu tekstowi wyświetlanemu przez polecenie ps
.
$ ps aux | grep 'ssh' root 2182 0.0 0.4 5172 952 ? Ss Nov05 0:00 /usr/sbin/sshd root 12170 0.0 1.1 8136 2472 ? Ss 07:12 0:01 sshd: root@pts/0 marek 12890 0.0 0.3 3908 728 pts/0 R+ 11:13 0:00 grep ssh $ ps aux | grep '[s]sh' root 2182 0.0 0.4 5172 952 ? Ss Nov05 0:00 /usr/sbin/sshd root 12170 ...
Get Bash. Receptury now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.