Interesting usage of the PV command with echo


The pv command which in full is pipe viewer is use to monitor the progress of data through pipe on the terminal. For instance when copying files with the cp command, you will only see an empty screen until its done. But with pv command who will be able to see the progress of the data transfer. We normally see this progress when downloading and installing packages.
The pv command therefore performs interestly when use with the echo command. The fascinating part is when used in bash scripting.

In this tutorial we will learn how to use the pv command with echo.

Install pv

On Debian, Ubuntu
$ sudo apt-get install pv

On Fedora, Redhat, Centos
$sudo yum install epel-release -y
$sudo yum install pv -y



 Usage with echo

$man pv

Let find out the manual on the command. With echo we will focus on the use of q and L options The -q (--quiet) option will suppress the output but its used with the -L option to limit the output by byte second. Run man pv



Now let use how to use the pv command with echo
$ echo "I love linux"
When echo is used without the pv command it just print out the text on the screen


Now let us pipe the output to the pv command.
$ echo "I love linux" | pv -qL 7.
The number indicates the byte it should print per second. So in the above example, it will print 7 bytes per second. The lower the number the slower the pv command print the output of echo.


Below is a play scripts that runs to welcome a new team member in our company. Run the below command to clone my scripts repository from github
$ git clone https://github.com/Nobleaxis/Scripts.git


Comments