Scroll to navigation

PV(1) User Commands PV(1)

NAME

pv - monitor the progress of data through a pipe

SYNOPSIS

pv [OPTION]... [FILE]...

pv [-pteIrab8kTv] [-A NUM] [-F FORMAT] [-x SPEC] [-Wgl0fc] [-D SEC] [-s SIZE] [-i SEC] [-m SEC] [-w WIDTH] [-H HEIGHT] [-N NAME] [-o FILE] [-L RATE] [-B BYTES] [-CESYKX] [-Z BYTES] [-U FILE] [-P FILE] [FILE ...]
pv -n [-trbv] [-Wl0] [-D SEC] [-s SIZE] [-i SEC] [-o FILE] [-L RATE] [-B BYTES] [-CESYKX] [-Z BYTES] [-U FILE] [-P FILE] [FILE ...]
pv -q [-v] [-s SIZE] [-o FILE] [-L RATE] [-B BYTES] [-CESYKX] [-Z BYTES] [-U FILE] [-P FILE] [FILE ...]
pv -R PID [-pteIrabT] [-A NUM] [-F FORMAT] [-s SIZE] [-i SEC] [-w WIDTH] [-H HEIGHT] [-N NAME] [-L RATE] [-B BYTES]
pv -d PID:FD [-pteIrab8kTnq] [-F FORMAT] [-i SEC] [-w WIDTH] [-H HEIGHT]
pv -d PID [-pteIrab8kTnq] [-F FORMAT] [-i SEC] [-w WIDTH] [-H HEIGHT]
pv -h
pv -V

DESCRIPTION

Show the progress of data through a pipeline by giving information such as time elapsed, percentage completed (with progress bar), current throughput rate, total data transferred, and ETA.

Each FILE is copied to standard output. With no FILE, or when FILE is “-”, standard input is read. This is the same behaviour as cat(1).

OPTIONS

Display switches

If no display switches are specified, pv behaves as if “--progress”, “--timer”, “--eta”, “--rate”, and “--bytes” had been given. Otherwise, only those display types that are explicitly switched on will be shown.

Turn the progress bar on. If any inputs are not files, or are unreadable, and no size was explicitly given with “--size”, the progress bar cannot indicate how close to completion the transfer is, so it will just move left and right to indicate that data is moving - or, with “--gauge”, the bar will indicate the current rate as a percentage of the maximum rate seen so far.
Turn the timer on. This will display the total elapsed time that pv has been running for.
Turn the ETA countdown on. This will estimate, based on current transfer rates and the total data size, how long it will be before completion. The countdown is prefixed with “ETA”. This option will have no effect if the total data size cannot be determined.
Turn the ETA countdown on, but display the estimated local time at which the transfer will finish, instead of the amount of time remaining. When the estimated time is more than 6 hours in the future, the date is shown as well. The time is prefixed with “FIN” for finish time. As with “--eta”, this option will have no effect if the total data size cannot be determined.
Turn the rate counter on. This will display the current rate of data transfer. The rate is shown in square brackets “[]”.
Turn the average rate counter on. This will display the current average rate of data transfer, over the last 30 seconds by default (see “--average-rate-window”). The average rate is shown in brackets “()”.
Turn the total byte counter on. This will display the total amount of data transferred so far.
Turn on the transfer buffer percentage display. This will show the percentage of the transfer buffer in use. Implies “--no-splice”. The transfer buffer percentage is shown in curly brackets “{}”.
Show the last NUM bytes written. Implies “--no-splice”.
Ignore all of the above options and instead use the format string FORMAT to determine the output format. See the FORMATTING section below.
Numeric output. Instead of giving a visual indication of progress, write an integer percentage, one per line, on standard error, suitable for passing to a tool such as dialog(1). Note that “--force” is not required if “--numeric” is being used.
Combining “--numeric” with “--bytes” will cause the number of bytes processed so far to be output instead of a percentage. Adding “--line-mode” as well as “--bytes” writes the number of lines instead of bytes or a percentage. Adding “--rate” adds the transfer rate to each output line (if “--bytes” is also in use, the rate comes after the byte/line count). Adding “--timer” prefixes each output line with the elapsed time so far, as a decimal number of seconds.
No output. Useful if the “--rate-limit” option is being used on its own to limit the transfer rate of a pipe.

Output modifiers

-8, --bits
Use bits instead of bytes for the byte and rate counters. The output suffix will be “b” instead of “B”.
Display and interpret suffixes as multiples of 1000 rather than the default of 1024. Note that this only takes effect on options after this one, so for consistency, specify this option first.
Wait until the first byte has been transferred before showing any progress information or calculating any ETAs. Useful if the program you are piping to or from requires extra information before it starts, such as when piping data into gpg(1) or mcrypt(1) which require a passphrase before data can be processed.
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. The value of SEC can be a decimal such as “0.5”.
Assume the total amount of data to be transferred is SIZE bytes when calculating percentages and ETAs. A suffix of “K”, “M”, “G”, or “T” can be added to denote kibibytes (*1024), mebibytes, gibibytes, tebibytes. If “--si” appears before this option, suffixes will denote kilobytes (*1000), megabytes, and so on instead.
If SIZE starts with “@”, the size of file whose name follows the @ will be used.
If the progress bar is shown but the size is not known, then instead of moving the bar left and right to show progress, show the current transfer rate as a percentage of the maximum rate seen so far.
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 “--size” will be interpreted as a line count.
If this option is used without “--size”, the "total size" (in this case, total line count) is calculated by reading through all input files once before transfer starts. If any inputs are pipes or non-regular files, or are unreadable, the total size will not be calculated.
-0, --null
Count lines as terminated with a null byte instead of with a newline. This option implies “--line-mode”.
Wait SEC seconds between updates. The default is to update every second. The value of SEC can be a decimal such as “0.1”.
Compute current average rate over a SEC seconds window for average rate and ETA calculations. The default is 30 seconds. The value must be an integer.
Assume the terminal is WIDTH columns wide, instead of trying to work it out (or assuming 80 if it cannot be guessed). If this option is used, the output width will not be adjusted if the width of the terminal changes while the transfer is running.
Assume the terminal is HEIGHT rows high, instead of trying to work it out (or assuming 25 if it cannot be guessed). If this option is used, the output height will not be adjusted if the height of the terminal changes while the transfer is running.
Prefix the output information with NAME. Useful in conjunction with “--cursor” if you have a complicated pipeline and you want to be able to tell different parts of it apart.
As well as displaying progress to the terminal, also write it to SPEC. The SPEC must start with a comma-separated list of destinations, and can optionally be followed by a colon and a format string. The destinations can be windowtitle or window for the xterm window title, and processtitle, proctitle, process, or proc for the process title displayed by ps(1). If a format string is not supplied, the same format is used as for the terminal. For example, “-x 'window,process:%t %b %r'” will show the elapsed time, bytes transferred, and rate, in both the window title and the process title.
At the end of the transfer, write an additional line showing the transfer rate minimum, maximum, mean, and standard deviation. The values are always in bytes per second (or bits, with “--bits”).
Force output. Normally, pv will not output any visual display if standard error is not a terminal. This option forces it to do so.
Use cursor positioning escape sequences instead of just using carriage returns. This is useful in conjunction with “--name” if you are using multiple pv invocations in a single pipeline.

Data transfer modifiers

Write data to FILE instead of standard output. If the file already exists, it will be truncated.
Limit the transfer to a maximum of RATE bytes per second. The same suffixes as “--size” can be used.
Use a transfer buffer size of BYTES bytes. The same suffixes as “--size” can be used. The default buffer size is the block size of the input file's filesystem multiplied by 32 (512KiB max), or 400KiB if the block size cannot be determined. This can be useful on platforms like MacOS with pipelines that perform better with specific buffer sizes such as 1024. Implies “--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 “--buffer-percent” and “--last-written” from working, cannot work with “--discard”, and makes “--buffer-size” redundant, so using any of those options automatically switches on “--no-splice”. Switching on this option results in a small loss of transfer efficiency. It has no effect on systems where splice(2) is unavailable.
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”.
Specify “--skip-errors” twice to only report a read error once per file, instead of reporting each byte range skipped.
When ignoring read errors with “--skip-errors”, instead of trying to adaptively skip by reading small amounts and skipping progressively larger sections until a read succeeds, move to the next file block of BYTES bytes as soon as an error occurs. There may still be some shorter skips where the block being skipped coincides with the end of the transfer buffer. The same suffixes as “--size” can be used.
This option can only be used with “--skip-errors” and is intended for use when reading from a block device, such as “--skip-errors --error-skip-block 4K” to skip in 4 kibibyte blocks. This will speed up reads from faulty media, at the expense of potentially losing more data.
If a size was specified with “--size”, stop transferring data once that many bytes have been written, instead of continuing to the end of input.
After every write operation, synchronise the buffer caches to disk with fdatasync(2). This has no effect when the output is a pipe. Using “--sync” may improve the accuracy of the progress bar when writing to a slow disk.
Set the O_DIRECT flag on all inputs and outputs, if it is available. This will minimise the effect of caches, at the cost of performance. Due to memory alignment requirements, it also may cause read or write failures with an error of “Invalid argument”, especially if reading and writing files across a variety of filesystems in a single pv call. Use this option with caution.
Instead of transferring input data to standard output, discard it. This is equivalent to redirecting standard output to /dev/null, except that write(2) is never called. Implies “--no-splice”.
Instead of passing data through immediately, do it in two stages - first read all input and write it to FILE, and then once the input is exhausted, read all of FILE and write it to the output. FILE remains in place afterwards, unless it is “-”, in which case pv creates a temporary file for this purpose, and automatically removes it afterwards.
This can be useful if you have a pipeline which generates data (your input) quickly but you don't know the size, and you wish to pass it to some slower process, once all of the input has been generated and you know its size, so you can see its progress. Note that when doing this with relatively small amounts of data, “--no-splice” may be preferable so that pipe buffering doesn't affect the progress display.
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 devices it opens will be shown with a progress bar. The pv process will exit when process PID exits.
Remotely control another instance of pv with process ID PID, making it act as though it had been given this instance's command line. For example, if “pv --rate-limit 123K” is running with process ID 9876, then running “pv --remote 9876 --rate-limit 321K” will cause process 9876 to start using a rate limit of 321KiB instead of 123KiB. Note that some options cannot be changed while running, such as “--cursor”, “--line-mode”, “--force”, “--delay-start”, “--skip-errors”, and “--stop-at-size”.

General options

Save the process ID of pv in FILE. The file will be replaced if it already exists, and will be removed when pv exits. While pv is running, FILE will contain a single number - the process ID of pv - followed by a newline.
Print a usage message on standard output and exit successfully.
Print version information on standard output and exit successfully.

FORMATTING

Format strings used by “--format” and “--extra-display” can contain the following sequences:

%p, %{progress}
Progress bar (suffixed with a percentage if the size is known). Equivalent to “--progress”. Expands to fill the remaining space unless prefixed by a number to set the width, such as “%20p” or “%20{progress}”.
%{progress-bar-only}
Progress bar, without any sides, and without any percentage displayed afterwards. Expands to fill the remaining space unless prefixed by a number.
%{progress-amount-only}
The percentage completion (or maximum rate, with “--gauge” when the size is unknown).
%t, %{timer}
Elapsed time. Equivalent to “--timer”.
%e, %{eta}
ETA as time remaining. Equivalent to “--eta”.
%I, %{fineta}
ETA as local time at which the transfer will finish. Equivalent to “--fineta”.
%r, %{rate}
Current data transfer rate. Equivalent to “--rate”.
%a, %{average-rate}
Average data transfer rate. Equivalent to “--average-rate”.
%b, %{bytes}, %{transferred}
Bytes transferred so far (or lines if “--line-mode” was specified). Equivalent to “--bytes”. If “--bits” was specified, “%b” shows the bits transferred so far, not bytes.
%T, %{buffer-percent}
Percentage of the transfer buffer in use. Equivalent to “--buffer-percent”. Displays “{----}” if the transfer is being done with splice(2), since splicing to or from pipes does not use the buffer.
%nA, %n{last-written}
Show the last n bytes written (for example, “%16A” shows 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.
%nL, %n{previous-line}
Show the first n bytes of the most recently written line (for example, “%40L” shows the first 40 bytes). If no n is given, then this expands to fill the available space. Shows only spaces if the transfer is being done with splice(2).
%N, %{name}
Show the name prefix given by “--name”. Padded to 9 characters with spaces, and suffixed with “:”.
%%
A single “%”.

Any other contents are reproduced in the progress display as-is.

The format string equivalent of the default display switches is “%b %t %r %p %e”.

EXAMPLES

Some suggested common switch combinations:

Show a progress bar, elapsed time, estimated completion time, byte counter, average rate, and current rate.
Show a progress bar, elapsed time, estimated completion time, line counter, and average rate, counting lines instead of bytes.
Show the amount transferred, elapsed time, current rate, and a gauge showing the current rate as a percentage of the maximum rate seen - useful in a pipeline where the total size is unknown. (If the size is known, these options will show the percentage completion instead of the rate gauge).
Show only the elapsed time - useful as a simple timer, such as “sleep 10m | pv -t”.
The default behaviour: progress bar, elapsed time, estimated completion time, current rate, and byte counter.

On MacOS, it may be useful to specify “--buffer-size 1024” in a pipeline, as this may improve performance.

To watch how quickly a file is transferred using nc(1):


pv file | nc -w 1 somewhere.com 3000

A similar example, transferring a file from another process and passing the expected size to pv:


cat file | pv -s 12345 | nc -w 1 somewhere.com 3000

A more complicated example using numeric output to feed into the dialog(1) program for a full-screen progress display:


(tar cf - . \
| pv -n -s $(du -sb . | awk '{print $1}') \
| gzip -9 > out.tgz) 2>&1 \
| dialog --gauge 'Progress' 7 70

Taking an image of a disk, skipping errors:


pv -EE /dev/your/disk/device > disk-image.img

Writing an image back to a disk:


pv disk-image.img > /dev/your/disk/device

Zeroing a disk:


pv < /dev/zero > /dev/your/disk/device

Note that if the input size cannot be calculated, and the output is a block device, then the size of the block device will be used and pv will automatically stop at that size as if “--stop-at-size” had been given.

(Linux only): Watching file descriptor 3 opened by another process 1234:


pv -d 1234:3

(Linux only): Watching all file descriptors used by process 1234:


pv -d 1234

Sending logs to a processing script, showing the most recent line as part of the progress display:


pv -F '%a %p : %L' big.log | processing-script

EXIT STATUS

An exit status of 1 indicates a problem with the “--remote” or “--pidfile” 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.

ENVIRONMENT

The following environment variables may affect pv:

The current user's home directory. This may be used by “--remote” to exchange messages between pv instances: if the /run/user/UID/ directory does not exist (where UID is the current user ID), then $HOME/.pv/ will be used instead.
The directory to create per-tty lock files for the terminal when using “--cursor”. If TMPDIR is set to a non-empty value, it is the directory under which lock files are created. Otherwise, TMP is used. If neither are set, then /tmp is used.

NOTES

In some versions of bash(1) and zsh(1), the construct “<(pv filename)” will not output any progress to the terminal when run from an interactive shell, due to the subprocess being run in a separate process group from the one that owns the terminal. In these cases, use “--force”.

If pv is used in a pipeline in zsh version 5.8, and the last command in the pipeline is based on shell builtins, zsh takes control of the terminal away from pv, preventing progress from being displayed. For example, this will produce no progress bar:


pv InputFile | { while read -r line; do sleep 0.1; done; }

To work around this, put the last commands of the pipeline in normal brackets to force the use of a subshell:


pv InputFile | ( while read -r line; do sleep 0.1; done; )

Refer to issue #105 for full details.

The “--remote” option requires that either /run/user/<uid>/ or $HOME/ can be written to, for inter-process communication.

The “--size” option has no effect if used with “--watchfd PID” to watch all file descriptors of a process, but will work with “--watchfd PID:FD” to watch a single file descriptor.

If the input size cannot be calculated, and the output is a block device, then pv will read the output device's size, use that as if it had been passed to “--size”, and activate “--stop-at-size”.

The “%nA” and “%nL” format sequences may not be effective with small input files, and “%nL” may be a few lines out due to buffering within the pipeline itself.

REPORTING BUGS

Please report any bugs to pv@ivarch.com.

Alternatively, use the issue tracker linked from the pv home page.

SEE ALSO

cat(1), dialog(1), splice(2), fdatasync(2), open(2) (for O_DIRECT)

COPYRIGHT

Copyright © 2002-2008, 2010, 2012-2015, 2017, 2021, 2023-2024 Andrew Wood.

License GPLv3+: GNU GPL version 3 or later.

This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.

Please see the package's ACKNOWLEDGEMENTS file for a complete list of contributors.

2024-12-08 pv-1.9.15