修改命令的連續輸出

~$ ping -c 1 google.com # unmodified output
PING google.com (16.58.209.174) 56(84) bytes of data.
64 bytes from wk-in-f100.1e100.net (16.58.209.174): icmp_seq=1 ttl=53 time=47.4 ms
~$ ping google.com | grep -o '^[0-9]\+[^()]\+' # modified output
64 bytes from wk-in-f100.1e100.net 
64 bytes from wk-in-f100.1e100.net 
64 bytes from wk-in-f100.1e100.net 
64 bytes from wk-in-f100.1e100.net 
64 bytes from wk-in-f100.1e100.net 
64 bytes from wk-in-f100.1e100.net 
64 bytes from wk-in-f100.1e100.net 
64 bytes from wk-in-f100.1e100.net 
64 bytes from wk-in-f100.1e100.net 
64 bytes from wk-in-f100.1e100.net 
...

管道(|)將 pingstdout 連線到 grepstdingrep 立即處理它。其他一些命令如 sed 預設緩衝他們的 stdin,這意味著它必須接收足夠的資料,然後才能列印任何內容,可能導致進一步處理的延遲。