Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm having problems when copy large files using nautilus (it gets stuck) so I need to copy using cp. I would like to know if there is any parameter that shows the % copied and also the transfer speed.

share|improve this question
12  
You could use rsync instead of cp. It has a --progress option. –  frostschutz Feb 17 '13 at 14:15
    
Midnight Commander also works well, and has a pretty text-based UI with progress bars, but might not be installed. Try mc on the command prompt. Also, obviously, it's not cp. –  Michael Kjörling Feb 17 '13 at 14:24
2  
Using rsync with --progress just made me figure out what is happening. It gets stuck when it reaches the 100%, and then last a couple of minutes in end up. I think is the same that is happening with nautilus. Anyway that is another question already, so the best answer for this question is the rsync --progress, it shows size, %, speed and elapsed time. –  yzT Feb 17 '13 at 15:16
    
I have a question about the rsync --progress. Assume that I have the directory A with files a and b and the empty directory B, when I copy A to B it shows the progress of each file, i.e. the progress of a and the progress of b. Is there any way to show the overall progress? –  yzT Feb 17 '13 at 15:33

5 Answers 5

If you allow other tools than cp it's surely possible. For a single file you can use pv. It's a small tool providing nice statistics.

pv inputfile > outputfile

If you have multiple files or directories you can use tar:

tar cf - sourceDirectory | pv | (cd destinationDirectory; tar xf -)

You can wrap it in a shell function. It's less to type and you get semantics close to the ones of cp. Here's a very simple (and not error-proof!) function:

cpstat () {
  tar cf - "$1" | pv | (cd "$2";tar xf -)
}

You call it like this

cpstat sourceDirectory destinationDirectory

You can enhance it further, so that pv provides an estimation of the remaining time.

Another solution (as frostschutz mentioned in a comment) is to use rsync with the --progress option:

rsync --progress -a sourceDirectory destinationDirectory
share|improve this answer
    
cpstat is going in the pastebin =) –  mtm Feb 17 '13 at 14:57
1  
This will give you transfer speed, but not ETA, because pv doesn't know how much data will come through the pipe. You can specify this using -s. E.g. first do du -sh sourceDirectory to get a (rough) idea, and then pass it to pv, like this: pv -s 100m. –  Jan Fabry May 11 at 15:25
up vote 16 down vote accepted

The nightly version of rsync has a new parameter called --info=progress2 which shows the overall %.

share|improve this answer

rsync works the best for showing the progress during the copying progress.

ex:

rsync -avh --progress sourceDirectory destinationDirectory
share|improve this answer
    
Do you realize this question was answered almost a year ago? –  yzT Jan 2 at 9:49
1  
@yzT do you know your are not the only person who is searching for this ? –  smonff Sep 7 at 10:30

Not in a standard version of cp.

You could background the cp and list the size while waiting for cp to finish.

I use this perl to monitor growth of a single file but it runs externally to the cp (or whatever else I'm doing)

share|improve this answer

Noticed this posting was somewhat old. But as I made a solution to the issue at hand, I thought I'd post my solution.

Scenario: We have a very large directory-structure we want to copy, so we issue the command cp -R sourcedir destdir in one terminal window.

Open another terminal window or push the process to the background (Ctrl+Z,bg<CR>), then let's make a progress indicator the ghetto way:

We first get the total size of the directory structure we want to copy, you do this with:

du -sh /path/sourcedirectory/

Convert the result to gigabytes (G), then substitute the n for the result you got in the variable sourcesize. Once you've inserted the sourcesize and destdir (destination directory), run the command below.

while true; do sourcesize=n destdir=/path/destinationdirectory/ copyprogress="$(export | du -sh $destdir | awk '{print $1}' | sed 's/[^0-9.]*//g' )" ; echo "scale=3 ; $copyprogress / $sourcesize * 100" | bc | xargs echo -n ; echo % completed ; sleep 10 ; done

This will print the progress every 10 seconds with messages like:

0.100% completed
0.200% completed
0.300% completed 
... etc

I'm aware that this solution did not address the speed of copying, but it would be possible to add that by by expanding the commands above, possibly making it into a bash script so it would be easier to read. For instance by checking how much data is copied pr. n time unit, the speed should be trivial to calculate and display.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.