輔助 | grep config 與 ps aux | grep config 對比grep "conf[g]"

輔助 | grep config 與 ps aux | grep config 對比grep "conf[g]"

我想知道為什麼在輸出中ps aux | grep包含該命令但沒有。grepps aux | grep "confi[g]"

$ ps aux | grep config
root               50   0.0  0.0  2548368   5760   ??  Ss   14Sep16   0:29.27 /usr/libexec/configd
emesa           20534   0.0  0.0  2434840    796 s002  S+    4:41PM   0:00.00 grep config

$ ps aux | grep "confi[g]"
root            15776   0.0  0.0  2519824    940   ??  Ss   Tue11AM   0:00.08 /System/Library/PrivateFrameworks/SystemAdministration.framework/XPCServices/writeconfig.xpc/Contents/MacOS/writeconfig
root               50   0.0  0.0  2547320   5740   ??  Ss   14Sep16   0:29.27 /usr/libexec/configd

答案1

因為grep "confi[g]"命令搜尋“配置”字串,在第二種情況下,該grep "confi[g]"指令不包含“配置”細繩。它包含“配置[g]”細繩。

ps這是一個常用的 grep 技巧,以避免在輸出中搜尋時列印 grep 命令過程。

相關內容