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

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
bar
Wordpress category: 

Comments

Of course, this can be done with just the links in /proc/pid/fd, /proc/pid/fdinfo and/or stat to follow the size of the file.