Duplication de la sortie standard : tee

Duplication de la sortie standard : tee

By ronan, 19 mai, 2012

La commande tee récupère un flux de données sur son entrée standard, l'envoie dans le fichier passé en argument et sur la sortie standard. Cela permet d'avoir à la fois le résultat à l'écran et dans un fichier.

Syntaxe

commande | tee [options] fichier
Principales options :
-a Ajoute à la fin de "fichier" si celui-ci existe déjà

Exemple

A partir du fichier /var/log/apache2/access.log, récupérer les lignes datant du 19/05/2012 en les affichant à l'écran et en les enregistrant dans un fichier

$ grep '19/May/2012' /var/log/apache2/access.log | tee 2012_05_19_log_apache
x.x.x.x - - [19/May/2012:14:49:03 +0200] "GET / HTTP/1.1" 200 7226 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0"
x.x.x.x - - [19/May/2012:14:49:04 +0200] "GET /node.css?7 HTTP/1.1" 200 664 "http://quennec.fr/" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0"
x.x.x.x - - [19/May/2012:14:49:04 +0200] "GET /defaults.css?7 HTTP/1.1" 200 718 "http://quennec.fr/" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0"
...
$

$ head -5 2012_05_19_log_apache
x.x.x.x - - [19/May/2012:14:49:03 +0200] "GET / HTTP/1.1" 200 7226 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0"
x.x.x.x - - [19/May/2012:14:49:04 +0200] "GET /node.css?7 HTTP/1.1" 200 664 "http://quennec.fr/" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0"
x.x.x.x - - [19/May/2012:14:49:04 +0200] "GET /defaults.css?7 HTTP/1.1" 200 718 "http://quennec.fr/" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0"
x.x.x.x - - [19/May/2012:14:49:05 +0200] "GET /layout.css?7 HTTP/1.1" 200 1444 "http://quennec.fr/" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0"
x.x.x.x - - [19/May/2012:14:49:05 +0200] "GET /style.css?7 HTTP/1.1" 200 7648 "http://quennec.fr/" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0"
$

Etiquettes