قالب وردپرس درنا توس
Home / Tips and Tricks / Monitoring the Progress of Linux Commands (with pv and progress)

Monitoring the Progress of Linux Commands (with pv and progress)



  Linux Terminal Command Prompt on a Laptop
Fatmawati Achmad Zaenuri / Shutterstock.com

Use the commands Linux pv and progress instead of dumbfound commands to pursue progress. These utilities give you progress bars for commands that do not normally have. The estimated time to completion is also displayed.

If you're on a long-haul flight on a plane with no video screens in the backrests, it's not easy to tell how far you are on your journey. You know when you took off. You know how long the flight is expected to last. But how do you know if you're on the right track, on time or far behind schedule? If you do not want to watch the movie during the flight, you can usually switch your video screen so that a map showing the position of your aircraft is displayed on it. You also get some statistics, eg. Eg the expected time of arrival (ETA).

Starting a command through the terminal window can sometimes feel like a long haul flight without a video screen. You have no clues as to whether everything is fine or whether the process has come to a standstill or how close he is to graduation. A flashing cursor is not very informative.

The commands pv and progress give you some statistics and a little visual feedback. You can see how close the process is to completion. That means you get an ETA for your running processes. Compared to staring at a cursor, that certainly wins.

Installing pv

You must install pv .

To install pv on Ubuntu, use this command: [1

9659010] sudo apt-get install pv

  sudo apt-get install pv in a terminal window

pv install on Fedora, use this command:

  sudo dnf install pv [19659014] sudo dnf install pv in a terminal window " width="646" height="57" src="/pagespeed_static/1.JiBnMqyl6S.gif" onload="pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);" onerror="this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);"/> 

To pv on Manjaro too install, use this command:

  sudo pacman -Syu pv 

  sudo pacman -Syu pv in a terminal window

with pv

pv stands for pipe viewer. Piping must be included somewhere in the command. Here is an example in which we pass an ISO image through zip to create a compressed ISO zip file.

To slow down the commands so that a screenshot can be taken, some of the files in the examples used for this article were stored on an old, slow external USB stick called SILVERXHD.

  pv /media/dave/SILVERXHD/gparted-live-1.0.0-1-amd64.iso | zip> gparted.zip 

  pv /media/dave/SILVERXHD/gparted-live-1.0.0-1-amd64.iso | zip> gparted.zip in a terminal window

The information pv is displayed in the bottom line of the display.

 pv output for creating a zip file in a terminal window

The following information is displayed from left to right:

  • The data transferred so far.
  • The time elapsed so far.
  • The data transfer rate (throughput).
  • A progress bar and percent graduation.
  • Estimated time remaining until completion.

Copying a file with pv

Copying a file with output from pv Use this command:

  pv /media/dave/SILVERXHD/gparted-live-1.0.0-1- amd64.iso> gparted.iso 

  pv /media/dave/SILVERXHD/gparted-live-1.0 .0-1-amd64.iso | gparted.iso in a terminal window

Copying the file displays a progress report.

 Copying a file with pv in a terminal window

Copying several files with pv [19659008] To copy several files and folders with pv we need to do a little trick. We use tar to move the files for us.

  tar -c help-files / | pv | tar -x -C Documents / 

  tar -c Help Files / | pv | tar -x -C documents / in a terminal window

The tar -c help files / part of the command instructs tar to create ( - c ) an archive of the files in the folder help-files. This is passed through pv so we get an indication of progress. It is then routed back to tar for the last part of the command. The archive is extracted ( -x ) and the directory is changed before being extracted into documents ([19459009-C).

So the files and folders that are in the help files are copied with a progress bar to the folder "Documents".

 Copying files with pv and tar in a terminal window

The output differs slightly this time.

There will be no ETA. The progress bar now displays a motion indicator. This shows that the process is active, but does not grow like a traditional progress bar from left to right. pv is limited to the display of information that can be extracted from the process to be submitted.

Creating an archive with pv and tar

Copying files with pv and tar does not leave an archive file. A kind of "virtual" archive is created by tar which is returned directly to tar to extract the files. If our goal is to copy files, this is 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 . The options used with tar are -c (create archive), -z (compress with gzip), and -f (filename of the archive).

Note that we use - as the file name, which causes tar to use stdout and writes its output to the terminal window. This output is not displayed as it is directed by pv .

The actual name of the archive is the file name to which the output of pv is directed. In this case it is "help-files.tgz".

  tar -czf - ./help-files/ | pv> help-files.tgz 

  tar -czf - ./help-files/ | pv> help-files.tgz in a terminal window

We get the same progress bars as before, and the archive file is created for us.

 Output of tar and pv in a terminal window

RELATED: Compressing and Extracting Files Using the tar Command on Linux

The options for the pv display

You can select a number of options Use this option with pv to change the details of the report.

If you use one of these options, all other options will be disabled. So, if you want to use three of the display options, you must specify these three options.

The use of pv without options corresponds to the use of -pterb options.

  • -p : Display of percentage completed. This is the progress bar and percent completion.
  • -t : Display of the elapsed time .
  • -e : Display of ] ETA .
  • -r : Display of the rate of the data transmission.
  • -b : Display of the byte count (previously transmitted data).
  • -n : Displays the percentage as integer . This outputs the completed percentage as an integer with each new update in a new row.

Repeat the last command and submit option -p (completed percentage) to pv .

  tar -czf - ./help-files/ | pv - p> help-files.tgz 

  tar -czf - ./help-files/ | pv - p> help-files.tgz in a terminal window

Disables all other display options. pv provides only the percentage completion element.

Since pv does not receive a percentage completion count of tar the progress bar is replaced by a movement indicator. There is no percentage.

 Output of pv and tar in a terminal window

Using pv with wc

We can use pv to pass a text file (or files) in wc . wc then counts the carriage returns, characters and words and pv gives us a progress report.

Here we redirect all ".page" files to the pipeline directory of help files in wc .

   pv. /Help-files/*.page | wc in a terminal window 

When wc is completed, we can see the number of line breaks (lines), characters, and words from all the ".page" files in the help-files folder. [19659004]   Output of pv and wc in a terminal window

Installing the progress command

The command outputs the same useful information as pv . However, it does work with a bunch of Linux commands.

To install progress in Ubuntu, use this command:

  sudo apt-get install progress 

  sudo apt-get install progress into a terminal window

to install progress in Fedora, use this command:

  sudo dnf install progress 

  sudo dnf install progress in a terminal widow

To install progress in Manjaro, use this command:

  sudo pacman -Su progress 

  sudo pacman -Syu progress In a terminal window

The progress of the commands works with

If you progress in a terminal window and press Enter, you will see a list of commands that will work with progress . [19659010] progress

  Output of command progress in a terminal window "width =" 646 "height =" 147 "src =" /pagespeed_static/1.JiBnMqyl6S.gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); onerror = "this.onerror = null; pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this);

Using Progress With Pipes

There are two techniques used to monitor commands with progress The first is the use of pipes.

The command tar is in the list of supported commands that can monitor progress so let's use tar . [19659004] The options we use are the default options -c (create archive), -z (compress with gzip) and -f [19459011Wewillcreateacompressedarchiveofeverythinginthe"help-files"folderandthearchivewillbenamed"helptgz"

We derive this from Progress and use the -m (monitor) option to continue progress reports on the process until it is completed.

  tar -czf help.tgz ./help-files/ | progress -m 

  tar -czf help.tgz ./help-files/ | progress -m in a terminal window

The terminal window displays the progress of the command tar when creating the archive.

 progress command monitors tar in a terminal window "width =" 646 "height =" 132 "src =" /pagespeed_static/1.JiBnMqyl6S.gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "onerror =" this.onerror = null; (This);

During processing, each file is listed with the following information:

  • The process ID.
  • The process name.
  • percentage complete.
  • Processed data and total file size.
  • Data rate (throughput).
  • Estimated time remaining (ETA).

You may see a second record. This first record is for tar . The second is for gzip . tar calls gzip to perform the compression. Since gzip is included in the list of supported commands, progress is reported about it.

Using progress in continuous monitoring mode

You can use progress in Continuous real-time monitoring mode with the -M option (monitoring).

Type the following command in a terminal window:

  progress -M 

  progress -M in a terminal window [19659004] progress reports that no commands are running for monitoring. However, they do not return to the command line. progress waits until a command is launched that it can monitor. It then automatically starts reporting.

 Waiting for the start of a command in a terminal window. "Width =" 646 "height =" 132 "src =" /pagespeed_static/1.JiBnMqyl6S.gif "onload =" pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this); "onerror =" this.onerror = null; pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon (this);

In another terminal window, type the command that specifies commands that progress can monitor.

We will use cat . Commands that finish too fast are not registered for progress so we list the contents of a very long text file.

  cat words.page 

  cat words.page in a terminal window

The terminal window with progress displays statistics for the command cat running and works towards the conclusion.

 Progress report on the cat in a terminal window

When Cat stops listing the file progress returns to the wait state.

Each time one of the commands is executed it can report that it is performing a large task Progress automatically monitors and reports them.

That's pretty neat.

100% done

Running command is doing, and pause your cursor with pv and progress [1 9459010].




Source link