Sun 2009-06-07 ( En pr )

Ever wanted to know how much longer your cp -r needs? This little Ruby script might help you.

$ cp2 coderay coderay-0.8
From: 307M	coderay
To:   154M	coderay-0.8

The second line updates every second while copying. It’s fast enough on OS X, but I’m sure it can be optimized.

Here’s the code:

#!/usr/bin/env ruby
puts <<USAGE unless ARGV.size == 2
cp progress printer (public domain)
Usage:
  cp2 FROM TO
USAGE
from, to = *ARGV
puts "From: " + `du -sh #{from}`
copy = Thread.new { `cp -r #{from} #{to}` }
$stdout.sync = true
loop do
  sleep 1
  print "\rTo:   ", `du -sh #{to}`.chomp
  break unless copy.alive?
end
copy.join
puts

Say something! / Sag was!

1
aYlNlfdX @ 19:26 on Tuesday, 2024-08-06
1
aYlNlfdX @ 19:26 on Tuesday, 2024-08-06
1
aYlNlfdX @ 19:32 on Tuesday, 2024-08-06
1
aYlNlfdX @ 19:32 on Tuesday, 2024-08-06
1
aYlNlfdX @ 19:33 on Tuesday, 2024-08-06
1
aYlNlfdX @ 19:33 on Tuesday, 2024-08-06
1
aYlNlfdX @ 19:37 on Tuesday, 2024-08-06
1
aYlNlfdX @ 19:37 on Tuesday, 2024-08-06
1
aYlNlfdX @ 20:02 on Tuesday, 2024-08-06
1
aYlNlfdX @ 20:02 on Tuesday, 2024-08-06

No markup, just plain monospace text. / Kein Markup, nur Normschrift-Klartext.