How to Copy at Command Line Showing Progress & Speed Indicator
Ever wished you could see the transfer progress and speed of copying files at the command line? If you’re familiar with the command line of Mac OS, Linux, or any other Unix operating system, you likely use the ‘cp’ or ditto commands to copy files, directories, and other data. The ditto and cp command is great, but one downside is that cp does not include a progress indicator, and that’s what we’re going to resolve here by creating an alias to use an rsync command with a progress indicator to copy data at the command line.
Obviously this is aimed at advanced users who use the command line for copying data, and who are comfortable with the concept of creating and using aliases within Terminal. If you’re a more novice user you’d probably be better off simply copying in Finder, duplicating files in the Mac Finder (which shows a visual progress bar), or using copy, cut, and paste for files in Mac Finder too.
How to Copy with a Progress & Speed Indicator at the Command Line on Mac
Again, we’ll be using rsync and an alias to create an alternate copy command with a transfer progress and speed indicator. This is covered with MacOS in mind, but it works the same with any other unix or Linux platform.
The basic rsync command we will use is as follows:
rsync -r --progress
But to make it easy to use again in the future repeatedly, we’re going to create an alias, so that ‘pcp’ will copy data with a progress indicator. Thus, the command becomes:
alias pcp="rsync -r --progress"
Assuming you use zsh (as most modern MacOS releases do, unless you changed your shell), you can add that to your .zshrc file as well to continue to use the copy with progress command.
Once the alias has been established, you can use the pcp command to copy and monitor the progress of the data copy. For example, you might try something like:
pcp ~/Downloads/GiantISO.iso /Volumes/Backups/GiantISO-backup.iso
You will see a progress indicator while copying with a percentage of the file copy, the data transfer rate, and time.
You can also use this with directories too, like so:
pcp /Backups/ImportantStuff /Backups2/
Again, you’ll see a progress indicator with percentage completed of the data copy, transfer rate, and time elapsed.
This is a super handy tip discovered on Twitter, cheers to @hoyd for sharing this, you can follow us on Twitter too if you’re into that sort of thing. If you have any additional tips, recommendations, suggestions, or alternatives to this approach to copying while showing progress and speed at the command line, share them with us in the comments.
If you enjoyed this tip, don’t miss our large archive of command line tips and tricks, there’s plenty more to learn!
so the time estimate becomes time progress once copy completes for each file
it shows transfer rate for the entire operation
but I don’t want to add up the times for all the files. how do I get a total time taken for unattended copy?
this is NOT showing time elapsed. This is showing estimated remaining time for each given file.
A total time for all files would be as helpful as a net transfer speed to benchmark these UFD
Using ⌃T (hold control-key and press T) sends a SIGINFO to the cp command which shows its status.
Not terribly well documented anywhere, but https://stuff-things.net/2016/04/06/that-one-stupid-dd-trick-and-the-ballad-of-siginfo/ is a decent read.
Thanks for this tip. I’m pretty good (not great) with command-line stuff and it is frustrating when copying not to know how long something is going to take or if something went wrong and things look as though they might have froze.
hi all. i’d suggest using this instead:
rsync -aX –progress
a flag is for archive, which implies all these: -rlptgoD
X = preserves extended attributes.
l = keep aliases/symlinks as they are
p = keep permissions
t= preserve mod times
That’s good except on macOS, -E (not -X) preserves extended attributes.
Perhaps of interest as well:
pv – monitor the progress of data through a pipe