CentOS7.9で標準出力をファイルに書き込む方法

環境

# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

書式
ping IPアドレス | tee ファイル名
teeコマンドを使用して、標準出力をファイルに書き込みます。

使用例
pingの結果をファイルresult.logに書き込みます
1.pingコマンドを実行します

# ping google.co.jp | tee result.log
PING google.co.jp (142.250.196.99) 56(84) bytes of data.
64 bytes from nrt12s35-in-f3.1e100.net (142.250.196.99): icmp_seq=1 ttl=128 time=27.7 ms
64 bytes from nrt12s35-in-f3.1e100.net (142.250.196.99): icmp_seq=2 ttl=128 time=8.48 ms
64 bytes from nrt12s35-in-f3.1e100.net (142.250.196.99): icmp_seq=3 ttl=128 time=8.69 ms
64 bytes from nrt12s35-in-f3.1e100.net (142.250.196.99): icmp_seq=4 ttl=128 time=12.7 ms
64 bytes from nrt12s35-in-f3.1e100.net (142.250.196.99): icmp_seq=5 ttl=128 time=7.73 ms
64 bytes from nrt12s35-in-f3.1e100.net (142.250.196.99): icmp_seq=6 ttl=128 time=8.51 ms
64 bytes from nrt12s35-in-f3.1e100.net (142.250.196.99): icmp_seq=7 ttl=128 time=7.59 ms
64 bytes from nrt12s35-in-f3.1e100.net (142.250.196.99): icmp_seq=8 ttl=128 time=8.53 ms

2.Ctrl +Cキーを押しながら停止します。

3.ファイルに書き込む結果を確認します

# cat result.log
PING google.co.jp (142.250.196.99) 56(84) bytes of data.
64 bytes from nrt12s35-in-f3.1e100.net (142.250.196.99): icmp_seq=1 ttl=128 time=27.7 ms
64 bytes from nrt12s35-in-f3.1e100.net (142.250.196.99): icmp_seq=2 ttl=128 time=8.48 ms
64 bytes from nrt12s35-in-f3.1e100.net (142.250.196.99): icmp_seq=3 ttl=128 time=8.69 ms
64 bytes from nrt12s35-in-f3.1e100.net (142.250.196.99): icmp_seq=4 ttl=128 time=12.7 ms
64 bytes from nrt12s35-in-f3.1e100.net (142.250.196.99): icmp_seq=5 ttl=128 time=7.73 ms
64 bytes from nrt12s35-in-f3.1e100.net (142.250.196.99): icmp_seq=6 ttl=128 time=8.51 ms
64 bytes from nrt12s35-in-f3.1e100.net (142.250.196.99): icmp_seq=7 ttl=128 time=7.59 ms
64 bytes from nrt12s35-in-f3.1e100.net (142.250.196.99): icmp_seq=8 ttl=128 time=8.53 ms

 

CentOS 7

Posted by arkgame