Otherwise, is there any alternative command line utility that can achieve this?
25 Answers
There isn't any progress or speed indicator in cp. See here as to why. Although it does more than you need, rsync has a --progress parameter. The -a will keep permissions, etc, and -h will be human readable.
rsync -ah --progress source destination
The output will look something like this:
Pictures/1.jpg
2.13M 100% 2.28MB/s 0:00:00 (xfr#5898, to-chk=1/5905)
Pictures/2.jpg
1.68M 100% 1.76MB/s 0:00:00 (xfr#5899, to-chk=0/5905)
- 11,750
While cp hasn't got this functionality, you can use pv to do this:
pv my_big_file > backup/my_big_file
Note: this method will lose the file's permissions and ownership. Files copied this way will have the same permissions as if you'd created them yourself and will belong to you.
In this example, pv basically just outputs the file to stdout*, which you redirect to a file using the > operator. Simultaneously, it prints information about the progress to the terminal when you do that.
This is what it looks like:
stefano@ubuntu:~/Data$ pv my_big_file > backup/my_big_file
138MB 0:00:01 [73.3MB/s] [=================================>] 100%
You may need to Install pv (alternatively, type sudo apt-get install pv) on your system.
*: The technical bit
There are three important streams of data in a unix-like system: stdout (standard output), stderr (standard error) and stdin (standard input). Every program has all three, so to speak. The > redirection operator redirects program output to a file. Without arguments, as you see above, > redirects a program's standard output to a file. cp basically does nothing fancier than
cat source > destination
(where cat just reads a file and prints it to stdout). pv is just like cat, but if you redirect it's output stream somewhere else, it will print progress information to stdout instead.
Take a look at man pv to learn more about it.
Another option, as DoR suggests in this answer, is to use rsync instead:
$ rsync -ah --progress source-file destination-file
sending incremental file list
source-file
621.22M 57% 283.86MB/s 0:00:01
This will preserve the files permissions/ownership while showing progress.
- 88,393
I get a kick out of using cURL for this exact purpose. The man page lists the "FILE" protocol as supported, so just use it like any other protocol in a URL:
curl -o destination FILE://source
Speed, progress, time remaining, and more -- all in a familiar format.
- 1,231
If you want to see if your files are transferring correctly you could use gcp and gcp is like cp but by default gives you a progress bar so that you can see what is being copied. As the program's wiki notes, gcp has several useful features such as
- transfer progression indication
- continuous copying on error (skip to next file)
- copy status logging: gcp logs all its actions so that it is possible to know which files have been successfully copied
- name mangling to handle target filesystem limitations (for example deletion of incompatible characters "*" or "?" on FAT)
However, even when the progress bar has reached 100% when using the tool, you must wait until your terminal prompt reappears before safely removing your media so that you can ensure that the transfer process has successfully finished.
gcp is used to copy files and has options such as --preserve so that various attributes and permissions can be preserved and --recursive so that whole directories can be copied. More information on its options can be found by entering man gcp or by going to the Ubuntu manpages online. A tutorial is also available on this site.
Install gcp from the repositories with
sudo apt-get install gcp
(Note: in Ubuntu 12.10 the new automount point is, for example, /media/user/usbdisk)
You can copy a file to your media by entering
gcp /home/mike/file.mp4 /media/usb
and copy a folder to your media with
gcp -rv ~/Podcasts /media/Mik2
Sample output from gcp with the progress bar:
gcp ~/Videos_incIplayer/mars.flv /media/Mik2
Copying 168.57 MiB 100% |########################################################| 7.98 M/s Time: 00:00:22
You can of course specify multiple files or folders to copy to your disk, and there are a lot of other options covered in man gcp.
There is a tool called progress in the repositories that is able to examine various different commands and display progress info for them.
Install it using the command
sudo apt-get install progress
This tool can be used like that:
cp bigfile newfile & progress -mp $!
Output:
[11471] cp /media/Backup/Downloads/FILENAME.file
29.9% (24.2 MiB / 16 MiB)
- 110,243
While it doesn't display speed when copying multiple files, the -v option to the cp command will provide you with progress info. e.g.
cp -rv old-directory new-directory
- 259
- 812
The kernel knows most of the data such as speed, and often also percentage. Modern kernels expose this via their /proc filesystem.
showspeed from https://github.com/jnweiger/showspeed uses that info. It can attach to already running programs and give periodic updates like this:
$ dd if=bigfile of=/tmp/otherbigfile &
$ showspeed dd
dd looks like a process name. pid=4417 matches av0=dd.
p/4417/fd/0r /home/jw/bigfile 113MB/s (12%, 2.3GB) 9m:35
p/4417/fd/1w /tmp/otherbigfile 182MB/s (2.6GB)
p/4417/fd/0r /home/jw/bigfile 285MB/s (15%, 3.0GB) 8m:08
p/4417/fd/0r /home/jw/bigfile 115MB/s (16%, 3.2GB) 8m:01
p/4417/fd/0r /home/jw/bigfile 107MB/s (17%, 3.4GB) 7m:39
p/4417/fd/1w /tmp/otherbigfile 104MB/s (3.5GB)
p/4417/fd/0r /home/jw/bigfile 139MB/s (19%, 3.7GB) 7m:37
p/4417/fd/0r /home/jw/bigfile 116MB/s (20%, 3.9GB) 7m:18
p/4417/fd/1w /tmp/otherbigfile 67MB/s (4.0GB)
p/4417/fd/1w /tmp/otherbigfile 100MB/s (4.1GB)
...
- 700
While pv can deal with local cp tasks, using dd with pv can deal with both local (cp) and remote (scp) tasks.
dd if=path/to/source.mkv | pv | dd of=path/to/dest.mkv
Please ensure the path/to/dest.mkv exits by touch path/to/dest.mkv
This can show the progress, but if you want the percentage information,
dd if=path/to/source.mkv | pv -s 100M | dd of=path/to/dest.mkv
Replace 100M above with the real size of your source file.
Here Comes the Remote Part
While scp can hardly show current progress, using dd with pv is a piece of cake.
ssh onemach@myotherhost dd if=path/to/source.mkv | pv -s 100M | dd of=path/to/dest.mkv
dd status=progress
Option added in GNU Coreutils 8.24+ (Ubuntu 16.04):
dd if=src of=dst status=progress
The terminal shows a line of type:
462858752 bytes (463 MB, 441 MiB) copied, 38 s, 12,2 MB/s
that gets regularly updated.
See also: How do you monitor the progress of dd?
- 31,312
If you have rsync 3.1 or higher (rsync --version), you can copy (cp -Rpn) while preserving permissions and ownership, recurse directories, "no clobber," and display overall progress (instead of just progress by file), copy rate, and (very rough) estimated time remaining with:
sudo rsync -a --info=progress2 --no-i-r /source /destination
Note that sudo is only needed if dealing with directories/files you don't own. Also, without the --no-i-r, the percentage may reset to a lower number at some point during the copy. Perhaps later versions of rsync will default to no-i-r with info=progress2, but it does not in the current version of 3.1.2.
I've found that the percentage and time remaining are grossly overestimated when copying to a directory that already contains files (ie. like when you would typically use cp -n "no clobber").
- 131
There's a new tool called cv that can find any descriptor related to a running command and show progress and speed: https://github.com/Xfennec/cv
cv -w
outputs the stats for all running cp,mv etc. operations
- 221
There are already some really great answers here, but here are my favorite commands, including my own little spin on the rsync command, with my favorite options:
1. watch 'du -hs' (or, for more granularity: watch -n 1 'du -sk | awk '\''{printf "%.3f MiB %s\n", $1/1024, $2}'\''') allows you to watch a destination folder grow in size if cp is already running
What if you already started a long cp process and don't want to stop it now?
Assuming you already started this copy command:
# recursively copy source_dir_name to destination
cp -r source_dir_name destination
Just open up a new terminal, with the copy operation already in progress, and run:
# cd into destination directory
cd path/to/destination/source_dir_name
Now watch, live, the size of this destination grow!
watch 'du -hs'
OR (Preferred!) see even more granularity, in X.xxx MiB:
watch 'du -sk | awk '''{printf "%.3f MiB %s\n", $1/1024, $2}''''
This will cause the watch command to automatically run du -hs (or du -sk | awk '{printf "%.3f MiB %s\n", $1/1024, $2}') every 2 seconds (the default for watch) inside your destination directory, so you can see the size of the folder grow in real-time! This doesn't give you a percentage complete, but if you have a rough idea of the size of what you're copying, it certainly gives you something to watch and feel good about, knowing the destination is growing. Here's a sample output on the watch screen:
Cmd:
watch 'du -hs'Output:
Every 2.0s: du -hs2.5G .
Cmd:
watch 'du -sk | awk '\''{printf "%.3f MiB %s\n", $1/1024, $2}'\'''Output:
Every 2.0s: du -sk | awk '{printf "%.3f MiB %s\n", $1/1024, $2}'2560.348 MiB .
Above, you can see the current size of the current directory (.) is 2.5 GiB, or, more specifically in the 2nd case: 2560.348 MiB. To make watch use a slower update interval, such as 5 seconds, just add -n 5 to the watch command, like this:
watch -n 5 'du -hs'
OR (preferred, for more granularity)
watch -n 5 'du -sk | awk '''{printf "%.3f MiB %s\n", $1/1024, $2}''''
2. rsync really is best for this
My favorite commands:
# dry-run
time rsync -rah --dry-run --info=progress2 --stats source destination
real copy (Important! Do a dry run first and read the
output summary to ensure you're copying what you intend!)
time rsync -rah --info=progress2 --stats source destination
Note: the time part at the front of the above commands just outputs a nice time summary of the total run-time for the operation in the end. This works before any Linux command.
Here's what an rsync --stats summary for a --dry-run looks like, by the way:
$ rsync -rah --dry-run --info=progress2 --stats /media/gabriel/cdrom ~/temp 2.76G 100% 2570.10GB/s 0:00:00 (xfr#3836, to-chk=0/4837)Number of files: 4,837 (reg: 3,836, dir: 1,001) Number of created files: 0 Number of deleted files: 0 Number of regular files transferred: 3,836 Total file size: 2.76G bytes Total transferred file size: 2.76G bytes Literal data: 0 bytes Matched data: 0 bytes File list size: 0 File list generation time: 0.001 seconds File list transfer time: 0.000 seconds Total bytes sent: 123.88K Total bytes received: 15.54K
sent 123.88K bytes received 15.54K bytes 278.85K bytes/sec total size is 2.76G speedup is 19,792.78 (DRY RUN)
References
- Place where I first documented the
watch -n 5 'du -sk | awk '\''{printf "%.3f MiB %s\n", $1/1024, $2}'\'''type command, in my ROS tutorial: my ROS.org tutorial: Reading messages from a bag file
Extra reading
- My long answer on some advanced
rsyncusage and stuff: Super User: Convert NTFS partition to ext4 - How to copy the data? - [another one of my answers] Unix & Linux: Is it possible to see cp speed and percent copied?
- 11,502
- 14
- 97
- 142
As many said, cp does not include this functionality.
Just to throw my $0.02, what I usually do with trivial copying situations (i.e. no -R):
See how big the file is and remember
Start copying
Open another terminal
Run
watch ls -lh DIRon the directory where the target is
This can keep me updated on target file size, with quite a minimum hassle.
As an alternative for less trivial situations, e.g. recursively copying directories, you can use watch du -hs DIR to see summary of DIR size. However du can take long to compute and can even slow down the copying, so you might want to use -n INTERVAL argument to watch so that trade-off is acceptable.
Update: In case you use wild-cards with command used with watch du, e.g. watch du -hs backup/*, don't forget to quote:
watch "du -hs backup/*"
otherwise the wild-cards will be expanded only once, when watch is started so du will not look at new files / subdirectories.
- 747
pv knows how to watch file descriptors given a pid, whether it's cp or something else
From the documentation:
(Linux only): Watching file descriptor 3 opened by another process 1234:
pv -d 1234:3
(Linux only): Watching all file descriptors used by process 1234:
pv -d 1234
Example:
md5sum file &
[1] + 1271 suspended
pv -d 1271
417MiB 0:00:17 [12,1MiB/s] [============> ] 29% ETA 0:00:53
$ cp file.mov copy.mov &
[2] 3731
$ pv -d 3731
3:/media/windows/file.mov: 754MiB 0:00:04 [97,2MiB/s] [======================> ] 52% ETA 0:00:07
4:/media/windows/copy.mov: 754MiB 0:00:04 [97,3MiB/s] [ <=> ]
- 295
Use a shell script:
#!/bin/sh
cp_p()
{
strace -q -ewrite cp -- "${1}" "${2}" 2>&1 \
| awk '{
count += $NF
if (count % 10 == 0) {
percent = count / total_size * 100
printf "%3d%% [", percent
for (i=0;i<=percent;i++)
printf "="
printf ">"
for (i=percent;i<100;i++)
printf " "
printf "]\r"
}
}
END { print "" }' total_size=$(stat -c '%s' "${1}") count=0
}
This will look like:
% cp_p /home/echox/foo.dat /home/echox/bar.dat
66% [===============================> ]
Depending on what you want to do, Midnight Commander (mc) might be the answer. I'm surprised it's not been mentioned yet.
Tools like pv or rsync are good to display progress of transfer of one huge file, but when it comes to copying whole directories/trees, mc calculates the size and then displays the progress very nicely. Plus it's available out of the box on majority of systems.
- 141
one more option to preserve attributes could be (if source is a folder it will be created in destination)
tar -c source | pv -e -t -p -r | tar -C destination -x
hope it may be useful to someone. To have estimated transfer time this can be acheived by doing do -s source in advance and passing it as a -s <size> parameter to pv.
- 121
As linux original cp has no this functionaliy, I used the following solution to get the progress information:
cp -a source_directory destination_direcotry
During the copy is working, create another command terminal and go to the source_directory as:
cd source_directory
du -sm .
After I got the total size of the source_directory, then go to the destination_direcotry to do the same work:
cd destination_direcotry
du -sm .
I could get the copying progress by comparining the total size difference between the destination_direcotry and the source_directory, the only extra work you need do is opening another terminal besides the cp terminal, to type "du -sm ." to get the total directory size you are coping.
- 1,015
- 1
- 13
- 17
Install gcp
sudo apt-get install gcp
NOTE: Make Sure you have enable X11 support if not: Add following line to '/etc/ssh/sshd_config'
ForwardX11Trusted yes
Install
sudo apt-get install xauth
reboot
When its done:
gcp -rv SOURCE_FOLDER DESTINATION_FOLDER
or:
gcp SOURCE_FILE DESTINATION_FILE
- 2,476
- 101
Not a perfect option you can open a second terminal and do
while true; do ls -lh [location/filename]; sleep 2; clear; done
It will show you the file in human readable format and you can watch the size of the file grow larger. I do this when I'm not able to install new utilities on the machine.
- 41
Single-liner pxargs shell for progress on xargs. Works everywhere, even busybox:
pxargs() (T="$(mktemp)" L=0; set +e; S=$(sed 's/\\/\\\\/g;'" s/'/'\\''/g" | xargs -n30 sh -c 'printf "$0 '\'%s\'' &\n" "$@"; printf "%s\n" wait '\''printf "\r'"$*"' progress: $((L += '\''$#'\'' + 2))/$S\r" >&2'\' "$*" |tee "$T" |wc -l); . "$T"; rm "$T"; echo)
This can be combined with find to print simple progress on a recursive copy:
progresscopy() (cpd() { cp -dpT "$1" "$D$1"; }; set -e; D=$(mkdir -p -- "$2"; cd -- "$2"; pwd)/; cd -- "$1"; find . -xdev -type d -exec sh -c 'cd "$0"; mkdir -p "$@"' "$D" "{}" "+" -o -print | pxargs cpd)
This finished copying 1.3GB of 30000 files in a few seconds, so its decently fast. The progress incremented from cpd progress: 0/30172 to cpd progress: 30172/30172 at finish.
- 251
- 3
- 8
You can copy use any program. At the same time, you can start sudo iotop and see the actually disk read/write speed yet without progress.
- 251
Check the source code for progress_bar in the below git repository
https://github.com/Kiran-Bose/supreme
Also try the custom bash script package supreme
Download the deb file and install in debian based distribution or download the source files, modify and use for other distros
Functionality overview
(1)Open Apps ----Firefox ----Calculator ----Settings
(2)Manage Files ----Search ----Navigate ----Quick access
|----Select File(s)
|----Inverse Selection
|----Make directory
|----Make file
|----Open
|----Copy
|----Move
|----Delete
|----Rename
|----Send to Device
|----Properties
(3)Manage Phone ----Move/Copy from phone ----Move/Copy to phone ----Sync folders
(4)Manage USB ----Move/Copy from USB ----Move/Copy to USB
- 119
