管道传输时打印到终端

管道传输时打印到终端
% ping -c 3 stackexchange.com | rev >/tmp/rping

保存 ping 和反向的结果。我想在执行此操作的同时将未反转的输出打印 ping到终端。我想实时执行此操作,而不是在ping完成后立即执行此操作。那可能吗?

答案1

使用三通:

ping -c 3 stackexchange.com | tee /dev/tty | rev >/tmp/rping

答案2

使用进程替换(假设您使用支持这些的 shell)将tee输出复制到终端:pingrev

$ ping -c 3 stackexchange.com | tee >(rev >/tmp/rping)
ping: Warning: stackexchange.com has multiple addresses; using 151.101.65.69
PING stackexchange.com (151.101.65.69): 56 data bytes
64 bytes from 151.101.65.69: icmp_seq=0 ttl=52 time=18.887 ms
64 bytes from 151.101.65.69: icmp_seq=1 ttl=52 time=18.514 ms
64 bytes from 151.101.65.69: icmp_seq=2 ttl=52 time=18.508 ms

--- stackexchange.com ping statistics ---
3 packets transmitted, 3 packets received, 0.0% packet loss
round-trip min/avg/max/std-dev = 18.508/18.636/18.887/0.177 ms

上述文本的输出不会有任何延迟ping

$ cat /tmp/rping
setyb atad 65 :)96.56.101.151( moc.egnahcxekcats GNIP
sm 788.81=emit 25=ltt 0=qes_pmci :96.56.101.151 morf setyb 46
sm 415.81=emit 25=ltt 1=qes_pmci :96.56.101.151 morf setyb 46
sm 805.81=emit 25=ltt 2=qes_pmci :96.56.101.151 morf setyb 46

--- scitsitats gnip moc.egnahcxekcats ---
ssol tekcap %0.0 ,deviecer stekcap 3 ,dettimsnart stekcap 3
sm 771.0/788.81/636.81/805.81 = ved-dts/xam/gva/nim pirt-dnuor

相关内容