Generic Top

The early-bird price of the new Learn Spring Security OAuth course packages will increase by $50 on Wednesday:

>> CHECK OUT THE COURSE

1. Overview

In this tutorial, we'll learn how to display copy progress and speed on Linux.

2. Single File

rsync is a file-copying tool that works for remote as well as local copies. It isn't always installed by default, but it's a popular tool and can be installed from standard repositories.

Let's use rsync to copy a single file while displaying progress. The destination can be a file or a directory:

rsync --progress /path/to/source-file /path/to/destination
source-file
    264,601,600  25%  126.22MB/s    0:00:06

We see the number of bytes copied so far, the progress percentage, speed, and time remaining.

3. Directory

Let's copy a directory using rsync while displaying the progress:

rsync -r --progress /path/to/source-dir /path/to/destination-dir
sending incremental file list
created directory /path/to/destination-dir
source-dir/
source-dir/1
    104,857,600 100%  261.70MB/s    0:00:00 (xfr#1, to-chk=8/10)
source-dir/2
    104,857,600 100%  102.46MB/s    0:00:00 (xfr#2, to-chk=7/10)
source-dir/3
    104,857,600 100%   58.11MB/s    0:00:01 (xfr#3, to-chk=6/10)
...

We can see that for recursive copy, rsync will show progress info for each file separately. What if we want to see overall progress instead?

Let's use a different option to see overall progress:

rsync -r --info=progress2 /path/to/source-dir /path/to/destination-dir
    423,297,024  44%  134.64MB/s    0:00:03  (xfr#4, to-chk=5/10)

This command will copy source-dir inside destination-dir. We can see the number of bytes copied, overall completion percentage, the total rate of transfer, and the time remaining. xfr#4 means four files were transferred so far, to-chk=5/10 means that out of ten files, five remain to be checked by rsync to see if they're up to date.

We should be aware that putting a slash at the end of source-dir will make rsync behave differently. This will copy the contents of source-dir, not source-dir itself:

rsync -r --info=progress2 /path/to/source-dir/ /path/to/destination-dir

4. Other Methods

We might not think of using curl, the URL transfer tool, to copy a file locally. It's possible, but for only one file at a time:

curl -o /path/to/destination-file file:///path/to/source-file
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
 17 1000M   17  173M    0     0   518M      0  0:00:01 --:--:--  0:00:01  518M

Let's use progress, a tool that will display the progress of basic commands already running, like cp, mv, dd, tar or gzip:

progress -M
[ 2498] cp /path/to/source-file
        80.7% (806.9 MiB / 1000 MiB) 245.0 MiB/s

Finally, let's try lsof, which can also be used to get information about a copy that's already in progress. We can monitor the changes using watch:

watch lsof /path/to/destination
COMMAND  PID USER   FD   TYPE DEVICE  SIZE/OFF   NODE NAME
cp      2197 root    4w   REG    8,2 650133504 539646 /path/to/destination

5. Conclusion

In this quick article, we learned how to see progress while copying files and directories on Linux.

Generic bottom

The early-bird price of the new Learn Spring Security OAuth course packages will increase by $50 on Wednesday:

>> CHECK OUT THE COURSE
Comments are closed on this article!