My *nix world

Monitor file (size) progress

From time to time I do several maintenance tasks that involve file copying, compressing, disk image cloning, etc.

Because sometimes (in fact almost always) these administrative task involves several commands that use the output/result of each other, I cannot use the GUI applications (which usually provides end-user feedback, like progress) but only CUI applications:


These programs, despite their strengths, don't provide a way to monitor file size progress while they're working. Of course, there are some workarounds, sometimes there even exists some additional software that one can use to satisfy this requirement (see my notes at the bottom). But I don't want too many dependencies (I have to depend on myself, so I think that's enough) so, when I have such a situation I use the following strategy:

  • knowing the source file size and watching continuously the target file size, I can approximate the percentage of work done

So what I do is basically:

  1. get the size of the source file (expressed in MB)
  2. list the target file and get its current size
  3. print on screen (echo) the result of 100*current_size/source_file_size


where target.file is the file which progress I do monitor and xxxx is the size of the file being copied.

But if you want to watch this process continuously, every 1 second, then you can automate this little bit. You can use the watch command where you can specify the command to watch every N seconds. The problem with this combination (our command and watch) is that the progress's value (100*current/total) is evaluated at the beginning, before the watch is starting using it. So watch is no use for us. Instead we can use a while loop, and the sleep command, like below:

where is just the command I shown you earlier.


Can that be made easier than this? Yes, it can. I wrote a bash script named fwatch (file watch) that allows me to specify the source and the target file, optionally the frequency for displaying the progress, and it provides me the current progress, nothing more, nothing less. I don't need to remember the whole line of the code, I don't need to check the source file size, the script does this by itself.

Using this script the only thing I have to do, instead the command I shown you earlier, is:


  • to monitor the progress of something that goes via a pipe, one may use the Pipe Viewer (pv command), though I never tried
  • to monitor the progress of dd command one may use the following trick:
    • find the process id for the dd command (like 'pgrep dd')
    • send the kill command to that process using a special USR1 signal; the dd command knows how to react to this particular signal, so in fact the dd command will print-out the current progress (i.e. kill -USR1 pid)

Now, if you think that this article was interesting don't forget to rate it. It shows me that you care and thus I will continue write about these things.

The following two tabs change content below.
Monitor file (size) progress

Eugen Mihailescu

Founder/programmer/one-man-show at Cubique Software
Always looking to learn more about *nix world, about the fundamental concepts of math, physics, electronics. I am also passionate about programming, database and systems administration. 16+ yrs experience in software development, designing enterprise systems, IT support and troubleshooting.
Tagged on: ,

Leave a Reply

Your email address will not be published. Required fields are marked *


Get every new post on this blog delivered to your Inbox.

Join other followers: