Instead of Flying Blindly, Use Linux Commands
progress to track the progress of the command. These utilities will give you progress bars for commands that don’t normally have them. You will also see the estimated time to completion.
If you’re on a long-haul flight without video screens in your seatbacks, it’s not easy to know how far you’ve traveled. You know when you took off. You know how long the flight will take. But how do you know you’re on the right track, on time, or way behind schedule? If you don’t want to watch a movie in flight, you can usually switch the video screen to show a map with your aircraft’s location on it. You also get some stats like expected time of arrival (ETA), which is great.
Running a command from a terminal window can sometimes feel like a long flight without a video screen. You have nothing to indicate if everything is fine, or the process is hung, or how close it is to completion. The blinking cursor is not very informative.
progress give you some stats and a little visual feedback. You can see how close the process is to completion. This means you get an ETA for your running processes. Compared to looking at the cursor, it wins hands down.
You must install
pv on Ubuntu, use this command:
sudo apt-get установить pv
pv on Fedora, use this command:
sudo dnf установить pv
pv on Manjaro, use this command:
Судо Пакман -Сю П.В.
pv denotes the viewer’s trumpet. The pipeline must be involved somewhere in the team. Here is an example where we pass the ISO image through
zip to create a compressed ISO zip file.
In order to slow down the commands enough to take a screenshot, some of the files in the examples used for this article were saved on an old slow external USB drive called SILVERXHD.
pv /media/dave/SILVERXHD/gparted-live-1.0.0-1-amd64.iso | zip> gparted.zip
Information is displayed from left to right:
- The data has been transferred so far.
- Time has gone far.
- Data transfer rate (bandwidth).
- Progress bar and percentage completed figure.
- Estimated time remaining to completion (ETA).
Copying a file with pv
To copy a file with output from
pv use this command:
pv /media/dave/SILVERXHD/gparted-live-1.0.0-1-amd64.iso> gparted.iso
We get a progress report as the file is copied.
Copying multiple files using PV
To copy multiple files and folders using
pv we need to use a little trick. We use
tar to move files for us.
tar -c help-files / | PV | tar -x -C Документы /
tar -c help-files/ part of the command indicates
tar create (
-c ) file archive in the help-files folder. It comes through
pv so we can see progress. It is then passed back to
tar for the last part of the command. The archive is extracted (
-x ) and the directory is changed (
-C ) on Documents before extracting.
So, the files and folders that are in the reference files are copied to the «Documents» folder with progress displayed.
This time the output is slightly different.
We do not receive an ETA. The progress bar now displays a moving bar. This shows that the process is active, but it does not grow from left to right like a traditional progress bar.
pv limited to displaying the information it can extract from the process that is being piped.
Using pv and tar to create an archive
Copying files using
tar doesn’t leave us with an archive file. Tar creates a kind of «virtual» archive that is fed back to
tar to extract files. If our goal is to copy files, this has been achieved. But what if we want to create an archive file?
We can still use
tar to create an archive file and get a progress report from
pv . Options used with
-c (create archive)
-z (compress with gzip) and
-f (archive file name).
Please note that we are using
- as the filename, which makes
tar use stdout and write its output to a terminal window. We do not see this output because it is passed through
The actual name of the archive will be the name of the file where we will pipe the output from
pv . In this case it is «help-files.tgz».
tar -czf - ./help-files/ | pv> help-files.tgz
RELATED: How to compress and extract files using the tar command in Linux
PV display options
There are a number of options that you can use with
pv to change the details of your report.
If you use any of these options, all other options are disabled. So if you want to use three display options, you need to specify those three options.
pv without any parameters is similar to using parameters
- -p : show percent execution. This is the progress bar and the percentage of the completed figure.
- -t : show past time .
- -e : display ETA .
- -r : show speed data transmission.
- -b : display quantity bytes (data transferred so far).
- -n : display percentage as whole number . This prints the percentage completed as an integer digit, with each new update on a new line.
Let’s repeat the last command and pass the option
-p (percent completed) in
tar -czf - ./help-files/ | pv - p> help-files.tgz
Using PV with WC
We can use
pv to transfer a text file (or files) to
wc . Then
wc will count carriage returns, characters and words, and
pv provide us with a progress report.
Here we send all the «.page» files from the help-files directory to
wc finishes, we’ll see the number of carriage returns (lines), characters, and words from all the «.page» files in the help-files folder.
Setting the progress command
progress gives the same useful information as
pv but it works with a specific set of Linux commands.
progress on Ubuntu, use this command:
sudo apt-get прогресс установки
progress on Fedora, use this command:
прогресс установки sudo dnf
progress in Manjaro, use this command:
Судо Пакман -Сю прогресс
Progress commands works with
progress in the terminal window and pressing Enter, you will get a list of commands with which it works
Using progress with pipes
There are two methods we can use to monitor commands with
progress . The first is the use of pipes.
tar is in the list of supported commands that can be tracked
progress so let’s use
We will use options
-c (create archive)
-z (compress with gzip) and
-f (File name). We are going to create a compressed archive of everything in the help files folder, and this archive will be called «help.tgz».
We connect it to
progress and use the option
-m (monitor) to
progress continued to report on the process until its completion.
tar -czf help.tgz ./help-files/ | прогресс -м
The terminal window will show the progress of the command
tar when creating an archive.