Overview
pv reads data from standard input and passes it to standard output, measuring the data flow and displaying the progress on the terminal. It is particularly useful for time-consuming tasks such as large file copying, compression, and network transfers.
Key Features
- Displays real-time data throughput
- Shows total data transferred
- Provides a progress bar and estimated time of arrival (ETA)
- Allows limiting data transfer speed
Key Options
The main options for the pv command are used for controlling data display, limiting speed, and specifying size.
Display and Control
Generated command:
Try combining the commands.
Description:
`pv` Executes the command.
Combine the above options to virtually execute commands with AI.
Usage Examples
Various examples of data transfer and monitoring using the pv command.
Basic Progress Monitoring
dd if=/dev/urandom bs=1M count=100 | pv > /dev/null
Monitor progress by sending data generated by dd to /dev/null using pv.
Monitoring File Copy Progress
pv large_file.iso > copied_file.iso
Display progress when copying a large file using pv. (Replace with actual file path)
Limiting Data Transfer Speed
dd if=/dev/zero bs=1M count=500 | pv -L 1m > /dev/null
Monitor progress while limiting the data transfer speed to 1MB per second.
Monitoring Compression Progress
tar -czf - my_directory | pv -s $(du -sb my_directory | awk '{print $1}') > archive.tar.gz
Check progress with pv when compressing a directory using tar and gzip. (Replace with actual directory path)
Specifying Total Size for Accurate ETA
dd if=/dev/urandom bs=1M count=500 | pv -s 500M > /dev/null
Inform pv that the total data size is 500MB to get more accurate progress and estimated completion time.
Installation
pv is not included by default in most Linux distributions, so it needs to be installed via a package manager.
Installation Commands
Installation commands for each operating system.
- Debian/Ubuntu: sudo apt update && sudo apt install pv
- CentOS/RHEL/Fedora: sudo yum install pv or sudo dnf install pv
- Arch Linux: sudo pacman -S pv
- macOS (Homebrew): brew install pv
Tips & Precautions
Tips and points to consider for more effective use of pv.
Usage Tips
- **Insert in the middle of a pipeline**: You can insert pv in the middle of a pipeline like `command1 | pv | command2` to monitor the progress of a specific stage.
- **Use -s for accurate ETA**: By dynamically specifying the total size in combination with commands like `du`, e.g., `pv -s $(du -sb large_dir | awk '{print $1}')`, you can get a more accurate ETA.
- **Manage bandwidth with speed limiting**: When transferring data over a network, using the `-L` option to control bandwidth can reduce the impact on other services.
- **Monitor files directly**: By providing a filename as an argument, such as `pv file.ext`, you can monitor the reading progress of that file.
Precautions
- **Buffering issues**: Some commands perform their own buffering, which might cause pv's progress to be displayed differently than expected. In such cases, check the buffering options of that command.
- **Terminal output interference**: Since pv continuously outputs progress to the terminal, when using pv in scripts, you might need to suppress output using options like `-q` (quiet).