Pv
pv ermöglicht, den Fortschritt einer Aktion oder Aufgabe durch eine sog. "Pipe" zu überwachen.
Beschreibung
Installation
# apt install pv
Syntax
pv [OPTIONEN]
- Beispielausgabe
24.2GB 0:44:21 [4.45MB/s] [=============> ] 40% ETA 1:05:38
Parameter
Optionen
Option | Beschreibung |
---|---|
-p | Zeigt einen Fortschrittsbalken an |
-t | Zeigt die vergangene Zeit an |
-e | Geschätzte verbleibende Zeit |
-r | Durchsatzrate anzeigen |
-a | Durchschnittliche Rateanzeige |
-n | Zeigt numerische Werte anstelle des Fortschrittsbalken an |
-W | Wartezeit bevor pv Statistiken anzeigt |
-i | Aktualisierungsintervall |
-L | Durchsatz festlegen |
-B | Puffergröße in Byte definieren |
-s | Größe in Bytes für Fortschritts- bzw. ETA-Berechnung |
-S | Stoppt Schreibvorgang bei Erreichen des Limits, z.B. der Partitionsgröße (erst ab Ubuntu 14.10) |
Anwendungen
- Eine Datei kopieren (mit Fortschrittsanzeige)
$ pv QUELLDATEI > ZIELDATEI
- Mit dd aus /dev/urandom lesen und nach /dev/null schreiben. Dabei werden 1000 MiB als 100% definiert
$ dd if=/dev/urandom bs=1M count=1000 | pv -petra -s 1000m > /dev/null
- Die Gerätedatei /dev/zero verwenden, um einen Datenträger mit Nullen zu überschreiben
# pv < /dev/zero > /dev/sdx
- pv übergibt eine 2 GiB große Datei wichtiges_backup.img an dd, das diese auf das (nicht-existente) Gerät "festplatte" schreibt
# dd if=/media/externe_festplatte/wichtige_backup.img | pv -s 2g | dd of=/dev/festplatte
- Öffne eine Datei mit cat und leite sie durch pv, wobei umfassende Statistiken erstellt werden.
Von dort wird an netcat (nc) übergeben, dass die Datei an ein System (Host) auf Port 7345 sendet:
$ cat datei | pv -petra | nc ubuntuusers.de 7345
# dd if=/dev/sda | pv -s 100G | pigz | ssh root@mx10.foxtom.de -p 2227 'dd of=/media/daten/backup/mx20/sdaMx20_2022-04-25.img.gz'
Dokumentation
Man-Pages
Info-Pages
Projekt-Homepage
Links
Siehe auch
Weblinks
Einzelnachweise
Testfragen
Testfrage 1
Testfrage 2
Testfrage 3
Testfrage 4
Testfrage 5
TMP 2
pv - überwacht den Fortschritt von Daten durch eine Pipe
SYNOPSIS
pv [OPTION] [FILE]... pv [-h|-V]
DESCRIPTION
- pv zeigt den Fortschritt von Daten durch eine Pipeline, indem Informationen wie verstrichene Zeit oder Prozentsatz angegeben werden abgeschlossen (mit Fortschrittsbalken), aktuelle Durchsatzrate, insgesamt übertragene Daten und ETA.
- Um es zu verwenden, fügen Sie es mit den entsprechenden Optionen in eine Pipeline zwischen zwei Prozessen ein. Sein Standard- put wird an seine Standardausgabe weitergeleitet und der Fortschritt wird auf dem Standardfehler angezeigt.
- pv kopiert jede gelieferte DATEI der Reihe nach auf die Standardausgabe (- bedeutet Standardeingabe), oder wenn keine DATEIEN vorhanden sind angegeben, wird nur die Standardeingabe kopiert. Dies ist das gleiche Verhalten wie bei cat(1).
Ein einfaches Beispiel, um zu sehen, wie schnell eine Datei mit nc(1) übertragen wird:
pv file | nc -w 1 somewhere.com 3000
Ein ähnliches Beispiel, bei dem eine Datei von einem anderen Prozess übertragen und die erwartete Größe an pv übergeben wird:
cat file | pv -s 12345 | nc -w 1 somewhere.com 3000
Ein komplizierteres Beispiel, bei dem eine numerische Ausgabe in das Programm dialog(1) für einen Vollbildmodus eingegeben wird Fortschrittsanzeige:
(tar cf - . \ | pv -n -s $(du -sb . | awk '{print $1}') \ | gzip -9 > out.tgz) 2>&1 \ | dialog --gauge 'Progress' 7 70
Ein Image einer Festplatte erstellen, Fehler überspringen:
pv -EE /dev/sda > disk-image.img
Zurückschreiben eines Images auf eine Festplatte:
pv disk-image.img > /dev/sda
Nullen einer Festplatte:
pv < /dev/zero > /dev/sda
Beachten Sie, dass, wenn die Eingabegröße nicht berechnet werden kann und die Ausgabe ein Blockgerät ist, die Größe der block wird verwendet und pv stoppt automatisch bei dieser Größe, als ob -S gegeben worden wäre.
(nur Linux): Beobachten von Dateideskriptor 3 geöffnet von einem anderen Prozess 1234:
pv -d 1234:3
(Nur Linux): Überwachen aller Dateideskriptoren, die von Prozess 1234 verwendet werden:
pv -d 1234
OPTIONS
pv takes many options, which are divided into display switches, output modifiers, and general options.
DISPLAY SWITCHES
pv akzeptiert viele Optionen, die in Anzeigeschalter, Ausgabemodifikatoren und allgemeine Optionen unterteilt sind.
ANZEIGESCHALTER
Wenn keine Anzeigeschalter angegeben sind, verhält sich pv so, als wären -p, -t, -e, -r und -b angegeben worden (dh alle außer Durchschnittsrate ist eingeschaltet). Ansonsten nur solche Anzeigetypen, die explizit sind eingeschaltet wird angezeigt.
-p, --progress
Schalten Sie den Fortschrittsbalken ein. Wenn die Standardeingabe keine Datei ist und keine Größe angegeben wurde (mit den Modifikatoren -s fier), kann der Fortschrittsbalken nicht anzeigen, wie kurz vor dem Abschluss der Übertragung steht, also wird er nur bewegen Sie sich nach links und rechts, um anzuzeigen, dass Daten verschoben werden.
-t, --timer
Turn the timer on. This will display the total elapsed time that pv has been running for.
-e, --eta
Turn the ETA timer on. This will attempt to guess, based on previous transfer rates and the total data size, how long it will be before completion. This option will have no effect if the total data size cannot be determined.
-I, --fineta
Turn the ETA timer on, but display the estimated local time of arrival instead of time left. When the estimated time is more than 6 hours in the future, the date is shown as well.
-r, --rate
Turn the rate counter on. This will display the current rate of data transfer.
-a, --average-rate
Turn the average rate counter on. This will display the average rate of data transfer so far.
-b, --bytes
Turn the total byte counter on. This will display the total amount of data transferred so far.
-T, --buffer-percent
Turn on the transfer buffer percentage display. This will show the percentage of the transfer buf‐ fer in use - but see the caveat under %T in the FORMATTING section below.
-A, --last-written NUM Show the last NUM bytes written - but see the caveat under %nA in the FORMATTING section below.
-F, --format FORMAT Ignore the options -p, -t, -e, -r, -a, -b, -T, and -A, and instead use the format string FORMAT to determine the output format. See the FORMATTING section below.
-n, --numeric
Numeric output. Instead of giving a visual indication of progress, pv will give an integer per‐ centage, one per line, on standard error, suitable for piping (via convoluted redirection) into di‐ alog(1). Note that -f is not required if -n is being used.
Note that if --numeric is in use, then adding --bytes will cause the number of bytes processed so far to be output instead of a percentage; if --line-mode is also in use, then instead of bytes or a percentage, the number of lines so far is output. And finally, if --timer is also in use, then each output line is prefixed with the elapsed time so far, as a decimal number of seconds.
-q, --quiet
No output. Useful if the -L option is being used on its own to just limit the transfer rate of a pipe.
OUTPUT MODIFIERS
-W, --wait
Wait until the first byte has been transferred before showing any progress information or calculat‐ ing any ETAs. Useful if the program you are piping to or from requires extra information before it starts, eg piping data into gpg(1) or mcrypt(1) which require a passphrase before data can be pro‐ cessed.
-D, --delay-start SEC
Wait until SEC seconds have passed before showing any progress information, for example in a script where you only want to show a progress bar if it starts taking a long time. Note that this can be a decimal such as 0.5.
-s SIZE, --size SIZE
Assume the total amount of data to be transferred is SIZE bytes when calculating percentages and ETAs. The same suffixes of "k", "m" etc can be used as with -L.
Has no effect if used with -d PID to watch all file descriptors of a process, but will work with -d PID:FD.
-l, --line-mode
Instead of counting bytes, count lines (newline characters). The progress bar will only move when a new line is found, and the value passed to the -s option will be interpreted as a line count. Note that file sizes are not automatically calculated when this option is used, to avoid having to read all files twice.
-0, --null
Count lines as null terminated. This option implies --line-mode.
-i SEC, --interval SEC
Wait SEC seconds between updates. The default is to update every second. Note that this can be a decimal such as 0.1.
-w WIDTH, --width WIDTH
Assume the terminal is WIDTH characters wide, instead of trying to work it out (or assuming 80 if it cannot be guessed).
-H HEIGHT, --height HEIGHT
Assume the terminal is HEIGHT rows high, instead of trying to work it out (or assuming 25 if it cannot be guessed).
-N NAME, --name NAME
Prefix the output information with NAME. Useful in conjunction with -c if you have a complicated pipeline and you want to be able to tell different parts of it apart.
-f, --force
Force output. Normally, pv will not output any visual display if standard error is not a terminal. This option forces it to do so.
-c, --cursor
Use cursor positioning escape sequences instead of just using carriage returns. This is useful in conjunction with -N (name) if you are using multiple pv invocations in a single, long, pipeline.
DATA TRANSFER MODIFIERS
-L RATE, --rate-limit RATE
Limit the transfer to a maximum of RATE bytes per second. A suffix of "K", "M", "G", or "T" can be added to denote kibibytes (*1024), mebibytes, and so on.
-B BYTES, --buffer-size BYTES
Use a transfer buffer size of BYTES bytes. A suffix of "K", "M", "G", or "T" can be added to de‐ note kibibytes (*1024), mebibytes, and so on. The default buffer size is the block size of the in‐ put file's filesystem multiplied by 32 (512KiB max), or 400KiB if the block size cannot be deter‐ mined.
-C, --no-splice
Never use splice(2), even if it would normally be possible. The splice(2) system call is a more efficient way of transferring data from or to a pipe than regular read(2) and write(2), but means that the transfer buffer may not be used. This prevents -A and -T from working, so if you want to use -A or -T then you will need to use -C, at the cost of a small loss in transfer efficiency. (This option has no effect on systems where splice(2) is unavailable).
-E, --skip-errors
Ignore read errors by attempting to skip past the offending sections. The corresponding parts of the output will be null bytes. At first only a few bytes will be skipped, but if there are many errors in a row then the skips will move up to chunks of 512. This is intended to be similar to dd conv=sync,noerror but has not been as thoroughly tested.
Specify -E twice to only report a read error once per file, instead of reporting each byte range skipped.
-S, --stop-at-size
If a size was specified with -s, stop transferring data once that many bytes have been written, in‐ stead of continuing to the end of input.
-d PID[:FD], --watchfd PID[:FD]
Instead of transferring data, watch file descriptor FD of process PID, and show its progress. The pv process will exit when FD either changes to a different file, changes read/write mode, or is closed; other data transfer modifiers - and remote control - may not be used with this option.
If only a PID is specified, then that process will be watched, and all regular files and block de‐ vices it opens will be shown with a progress bar. The pv process will exit when process PID exits.
-R PID, --remote PID
If PID is an instance of pv that is already running, -R PID will cause that instance to act as though it had been given this instance's command line instead. For example, if pv -L 123K is run‐ ning with process ID 9876, then running pv -R 9876 -L 321K will cause it to start using a rate limit of 321KiB instead of 123KiB. Note that some options cannot be changed while running, such as -c, -l, -f, -D, -E, and -S.
GENERAL OPTIONS
-P FILE, --pidfile FILE
Save the process ID of pv in FILE. The file will be truncated if it already exists, and will be removed when pv exits. While pv is running, it will contain a single number - the process ID of pv - followed by a newline.
-h, --help
Print a usage message on standard output and exit successfully.
-V, --version
Print version information on standard output and exit successfully.
FORMATTING
If the -F option is given, then the output format is determined by the given format string. Within that string, the following sequences can be used:
%p Progress bar. Expands to fill the remaining space. Should only be specified once. Equivalent to
-p.
%t Elapsed time. Equivalent to -t.
%e ETA as time remaining. Equivalent to -e.
%I ETA as local time of completion. Equivalent to -I.
%r Current data transfer rate. Equivalent to -r.
%a Average data transfer rate. Equivalent to -a.
%b Bytes transferred so far (or lines if -l was specified). Equivalent to -b.
%T Percentage of the transfer buffer in use. Equivalent to -T. Shows "{----}" if the transfer is be‐ ing done with splice(2), since splicing to or from pipes does not use the buffer.
%nA Show the last n bytes written (e.g. %16A for the last 16 bytes). Shows only dots if the transfer is being done with splice(2), since splicing to or from pipes does not use the buffer.
%N Name prefix given by -N. Padded to 9 characters with spaces, and suffixed with :.
%% A single %.
The format string equivalent of turning on all display switches is `%N %b %T %t %r %a %p %e'.
COMMON SWITCHES
Some suggested common switch combinations:
pv -ptebar
Show a progress bar, elapsed time, estimated completion time, byte counter, average rate, and cur‐ rent rate.
pv -betlap
Show a progress bar, elapsed time, estimated completion time, line counter, and average rate, counting lines instead of bytes.
pv -t
Show only the elapsed time - useful as a simple timer, e.g. sleep 10m | pv -t.
pv -pterb
The default behaviour: progress bar, elapsed time, estimated completion time, current rate, and byte counter.
EXIT STATUS An exit status of 1 indicates a problem with the -R or -P options.
Any other exit status is a bitmask of the following:
2 One or more files could not be accessed, stat(2)ed, or opened.
4 An input file was the same as the output file.
8 Internal error with closing a file or moving to the next file.
16 There was an error while transferring data from one or more input files.
32 A signal was caught that caused an early exit.
64 Memory allocation failed.
A zero exit status indicates no problems.
KNOWN PROBLEMS
The following problems are known to exist in pv:
- The -c option does not work properly on Cygwin without cygserver running, if started near the bot‐
tom of the screen (IPC is needed to handle the terminal scrolling). To fix this, start cygserver before using pv -c.
- The -R option is not available on Cygwin without cygserver running (SYSV IPC is needed). To fix
this, start cygserver before running the instance of pv you want, at runtime, to change the parame‐ ters of.
SEE ALSO
cat(1), dialog(1), splice(2)