Monitor the progress of cp/mv with lsof and Term::ProgressBar

Powered by Drupal
Submitted by raf on Sat, 10/10/2009 - 19:35
Preparing for another move of large files, I was considering ways to see the progress of the file operations. Then I remembered that lsof includes the size of the open files in its output. I wrote a small Perl script that starts the file operation in another process, and then use lsof to monitor its progress. I used the size of the source and destination file to create a progress-bar. lsof can be run in repeat mode (-r), I combined this with the process id (-p) and the (known) read and write file descriptor (-d).
$ bar cp /data/cd.iso .
cd.iso:  75% [====================================    *        ]0m22s Left