gnu coreutils split verbose gespült?

653
719016

splitWie kann ich bei Verwendung des GNU- Befehls coreutils im Verbose-Modus die Zeilen, die im STDOUT angezeigt werden, in Bezug auf den Zeitpunkt leeren lassen, zu dem die Datei endgültig erstellt wurde?

Zum Beispiel, es so laufen lassen:

~/coreutils/bin/split --verbose -d -u -l 10000000 1>out & tail -f out creating file `x00' creating file `x01' creating file `x02' [...] 

Ich hätte erwartet, dass die Zeile creating file 'x00'in der Datei erscheint, outnachdem die Datei vollständig geschrieben wurde. Stattdessen scheint es, als würde nichts geschrieben, outbis die gesamte Datei endgültig verarbeitet wurde. Gibt es eine Möglichkeit, dieses Verhalten zu ändern?

0
Ich denke, dass alle GNU-Coreutils Ausgabepuffer verwenden, so dass sie erst dann etwas ausgeben, wenn der Puffer gefüllt ist oder wenn die Ausgabe ein interaktives Terminal ist. MV. vor 11 Jahren 0
Die Ausgabe an stdout wird gepuffert, stderr nicht. lornix vor 11 Jahren 0

1 Antwort auf die Frage

1
MV.

Ok, old versions of GNU coreutils (before 7.5) don't have an easy workaround (as far as I know), but newer versions (since 7.5) have a stdbuf command you can use to force split (or any other coreutil program) to immediately print its output. In your case, you can use:

~/coreutils/bin/stdbuf -o0 ~/coreutils/bin/split --verbose -d -u -l 10000000 1>out & tail -f out 

That will run split with output buffering disabled.

Please note the -u option (unbuffered) in split does not affect the message printing, only the data it's splitting (it feels slower if you disable that buffering).

Information about stdbuf: http://www.gnu.org/software/coreutils/manual/html_node/stdbuf-invocation.html

For an alternative when using older coreutils versions, check this solution using command unbuffer from the package expect (tcl): https://unix.stackexchange.com/questions/25372/turn-off-buffering-in-pipe