我systemctl status name.service | grep Active
得到以下信息:
Active: active (running) since Mon 2018-05-14 21:44:09 CEST; 5s ago
我怎样才能获得相同的信息,但没有:“Active:”?
答案1
您可以使用
grep -oP 'Active: \K.*'
打印不带“Active:”的行:
$ systemctl status ssh.service | grep Active
Active: active (running) since Sat 2018-03-31 14:15:07 CEST; 1 months 13 days ago
$ systemctl status ssh.service | grep -oP 'Active: \K.*'
active (running) since Sat 2018-03-31 14:15:07 CEST; 1 months 13 days ago
-o
告诉grep
仅打印匹配行的匹配部分-P
启用 Perl 兼容正则表达式 (PCRE),这是使用时需要的\K
,它会使匹配的文本远离整体正则表达式匹配。