pv command in Linux with Examples
Last Updated :
05 Sep, 2024
The ‘pv’ command, short for Pipe Viewer, is a terminal-based tool in Linux used to monitor data flow through pipes. It provides a visual representation of the progress, making it easier to track the status of long-running data transfers. The ‘pv’ command is particularly useful for monitoring data being sent through pipelines, providing real-time updates on data transfer, elapsed time, throughput rate, and more.
Key Features of the pv Command
‘pv’ helps the user by giving him a visual display of the following:
- Time Elapsed: Shows the total time taken since the transfer began.
- Completed Progress: Displays a percentage progress bar of the transfer.
- Current Data Transfer Speed: Also known as the throughput rate, it shows how quickly data is being transferred.
- Data Transferred: Indicates the amount of data transferred so far.
- ETA (Estimated Time): Provides an estimated remaining time for the transfer based on the current data rate.
Installing the ‘pv’ command
The ‘pv’ command is available in most Linux distributions and can be installed using the package manager specific to your system.
1. For Debian based distributions:
$ apt-get install pv
2. For RedHat based distributions
$ yum install pv
How to use the ‘pv’ command?
pv is used to provide the ability of monitoring progress of a given application which lacks the mentioned functionality. It can be used by placing a pipe operator (|) between two processes.
Syntax of pv command:
pv fileName
pv OPTIONS fileName
pv fileName > outputFileName
pv OPTIONS | command > outputFileName
command1 | pv | command2
Standard Input of the pv command is passed to Standard Output and then the result is printed to Standard Error.
Key Options for ‘pv’ command
1. General Options
- ‘-help’: Displays the usage information.
- ‘–version’: Displays the version information.
2. Display Modifiers
- ‘–progress/-p’: Displays the progress bar.
- ‘–timer/-t’: Displays the elapsed time.
- ‘–eta/-e’: Displays the Estimated Time for the operation. Guess for the time is based on the previous data transfer rate and the size of data to be transferred.
- ‘–rate/-r’: Turns on the rate counter for the operation.
- ‘–bytes/-b’: Displays the total amount of data transferred till now.
- ‘–numeric/-n’: Displays integer percentage instead of the visual representation.
- ‘–quiet/-q’: No output
3. Output Modifiers
- –wait / -W : To wait for transfer of first byte before displaying progress.
- –interval SECONDS / -i SECONDS : Specified the time interval between updates.
- –force / -F : Forces an operation, i.e. forces pv to display visuals even when Standard Error is not a terminal.
- –size SIZE / -s : Assume the total data to be transferred is SIZE bytes for calculating computing percentage or ETA.
- –line-mode / -L : Instead of counting size, progress bar will move if new line is found.
- –name NAME / -n NAME : Prefix output info with name.
- –cursor / -c : Use cursor positioning escape sequence instead of using carriage returns.
4. Data Transfer Modifier
- –rate-limit RATE / -L RATE : Limit transfer to max of RATE byte per second.
- –buffer-size BYTES / -B BYTES : Use transfer buffer size of BYTE bytes.
- –remote PID / -R PID : If PID is instance of pv, will cause that instance to act, through it has been given instance’s command line instead.
When no option is selected -p, -t, -e, -r, -b options are selected by default.
pv command Examples in Linux
Let us look at some of the examples of ‘pv’ command in Linux to better understand the concept.
1. Creating a progress bar with the copy command
$ pv history.log > $HOME/Documents/history.log

2. Making zip with the progress bar
$ pv history.log | zip>$HOME/Documents/history.zip

3. Count number of lines, words, bytes
$ pv -p history.log | wc

4. Monitor tar progress
$ tar -czf - ./Documents/ | (pv -p --timer --rate --bytes > backup.tgz)

Conclusion
The ‘pv’ command is an invaluable tool for monitoring data transfers in Linux, offering real-time visual feedback on progress, speed, and estimated completion times. It enhances the visibility of data pipelines, especially for processes that do not natively support progress reporting. By learning how to use ‘pv’ and its different options, you can effectively monitor and manage your data transfers, making it a valuable tool for any Linux user or administrator who works with data processing tasks.
Similar Reads
pmap command in Linux with Examples
The pmap command in Linux is a powerful utility used to display the memory map of a process. A memory map provides insight into how memory is allocated and distributed within a running process. This can be incredibly useful for developers and system administrators when debugging memory issues, optim
4 min read
df Command in Linux with Examples
There might come a situation while using Linux when you want to know the amount of space consumed by a particular file system on your LINUX system or how much space is available on a particular file system. LINUX being command friendly provides a command line utility for this i.e. 'df' command that
9 min read
printf command in Linux with Examples
The 'printf' command in Linux is a versatile tool used to display formatted text, numbers, or other data types directly in the terminal. Like the 'printf' function in programming languages like C, the Linux printf command allows users to format output with great precision, making it ideal for script
4 min read
vmstat command in Linux with Examples
vmstat command in Linux/Unix is a performance monitoring command of the system as it gives the information about processes, memory, paging, block IO, disk, and CPU scheduling. All these functionalities makes the command vmstat also known as virtual memory statistic reporter. The very first report pr
3 min read
vnstat command in Linux with Examples
vnstat is a command-line tool in Linux that is generally used by system administrators in order to monitor network parameters such as bandwidth consumption or maybe some traffic flowing in or out. It monitors the traffic on the system's network interfaces. Installing vnstat on LinuxIn case of RedHa
4 min read
dc command in Linux with examples
The dc command is a versatile calculator found in Linux systems, operating using reverse Polish notation (RPN). This command allows users to perform arithmetic calculations and manipulate a stack, making it ideal for complex mathematical tasks directly from the command line. SyntaxThe basic syntax f
3 min read
pstree Command in Linux with Examples
The pstree command in Linux is a powerful tool that displays running processes as a tree structure. This visual representation makes it easier to understand the hierarchy of processes, providing a more intuitive view of how processes are related to each other. The root of the tree is either the `ini
3 min read
ed command in Linux with examples
Linux 'ed' command is used to start the ed text editor, a very minimal fronted line-based text editor. The lines are very simple in relation to other text files, hence easy to work on, for creating as well as editing, display, and manipulation of files. Since it was the first editor that was include
4 min read
mpstat Command in Linux with Examples
mpstat is a powerful and versatile command-line tool within a Linux system that allows detailed reporting of various processor-related statistics. Indeed, part of the sysstat package, mpstat delivers comprehensive CPU utilization and performance data, thus becoming an essential utility for both syst
5 min read
read command in Linux with Examples
read command in the Linux system is used to read from a file descriptor. This command reads up the total number of bytes from the specified file descriptor into the buffer. If the number or count is zero, this command may detect errors. But on success, it returns the number of bytes read. Zero indic
3 min read