LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-27-2009, 06:43 PM   #16
surfreak
LQ Newbie
 
Registered: May 2009
Posts: 4

Rep: Reputation: 0

Found this, anyone want to decode it a bit?

From http://chris-lamb.co.uk/2008/01/24/c...bar-like-wget/ (safe)



#!/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
}
 
Old 10-02-2009, 01:54 PM   #17
Hackeron
LQ Newbie
 
Registered: Oct 2003
Posts: 18

Rep: Reputation: 0
Question

I generally use rsync -aP to copy to see a progress, but it shows a progress on a per file basis and a file count.

Is there anything that will show the overall progress based on size left to copy?
 
Old 11-07-2009, 01:02 AM   #18
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,561

Rep: Reputation: 57
Quote:
Originally Posted by homey View Post
Here's another sample which maybe abit more usefull.

Code:
#!/bin/bash
# File copy with progress indicators
# Example: ./test original_file destination_file

usage()
{
   echo "Usage: $0 original_file destination_file"
   exit 1;
}

test $# == 2 || usage

echo Preparing to copy
orig_size=$(stat -c %s $1)

>$2
dest_size=0
cp -f $1 $2 &

while [ $orig_size -gt $dest_size ] ; do
   dest_size=$(stat -c %s $2)
   pct=$((( 100 * $dest_size ) / $orig_size ))

if [ $pct -lt 10 ] ; then
   echo -en "#  $pct%\b\b\b\b"
else
   echo -en "#  $pct%\b\b\b\b\b"
fi
sleep 1
done
echo
And here is another....
Code:
#!/bin/bash
# Example: ./test original_file destination_file
usage()
{
   echo "Usage: $0 original_file destination_file"
   exit 1;
}

test $# == 2 || usage
orig_size=$(stat -c %s $1)

>$2
dest_size=0
cp -f $1 $2 &

while [ $orig_size -gt $dest_size ] ; do
   dest_size=$(stat -c %s $2)
   pct=$((( 69 * $dest_size ) / $orig_size ))

    echo -en "\r["
    for j in `seq 1 $pct`; do
        echo -n "="
    done
    echo -n ">"
    for j in `seq $pct 68`; do
        echo -n "."
    done
    echo -n "] "
    echo -n $((( 100 * $pct ) / 69 ))
    echo -n "%"
done
echo
those results. Could they be in official Debian packages?

that's just a tar.gz to make, and send a file chmoded to :
/usr/bin/ such as hcp
or progressbarcp

It would be could to be in the repositories

or the very best would be to be into cp itself

such as
Code:
cp -p file.ext target.ext
with -p for progress bar added




Damn right you can.
Quote:
#!/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
}
In action:
Quote:
% cp_p /mnt/raid/pub/iso/debian/debian-2.2r4potato-i386-netinst.iso /dev/null
76% [===========================================> ]
the not good part 30 to 50pct:
Quote:
Be aware, however, that this adds quite some overhead (30% to 50% in my tests) to the time needed to copy a file. A probably better way would be to use <code>dd</code> under the hood and get its progress status by <code>kill -USR1 $PID</code>. You lose all switches that <code>cp</code> understands, however.
In the end it would probably be better to add a switch to <code>p</code>.

Last edited by frenchn00b; 11-07-2009 at 01:10 AM.
 
Old 01-26-2010, 01:01 PM   #19
DeNayGo
Member
 
Registered: Jun 2005
Location: Aachen, Germany
Distribution: Debian
Posts: 74

Rep: Reputation: 16
I know this thread is getting kinda old, but there doesn't seem to be another _real_ solution, yet, so here's mine:

http://www.beatex.org/web/advancedcopy.html

It's a patch for the original GNU coreutils.

This does exactly what the creator of this thread had in mind. All you have to do is add -g to cp and you have one overall and one per file progress bar to entertain you while you're waiting
 
Old 01-27-2010, 04:42 PM   #20
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,561

Rep: Reputation: 57
I experimented :

Code:
rsync -ruva --progress source1 target1
that's the best cuz one can do CTRL + C to break during processss .

no?
 
Old 01-27-2010, 04:44 PM   #21
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,561

Rep: Reputation: 57
Quote:
Originally Posted by DeNayGo View Post
I know this thread is getting kinda old, but there doesn't seem to be another _real_ solution, yet, so here's mine:

http://www.beatex.org/web/advancedcopy.html

It's a patch for the original GNU coreutils.

This does exactly what the creator of this thread had in mind. All you have to do is add -g to cp and you have one overall and one per file progress bar to entertain you while you're waiting

that's nice but you have to consider this, that advanced cp has to have too :

cp -R

cp -a

cp -u

...
and so on ... those are highly important for various uses.
Our cp function, the standard, is already very advanced and serves all sorts of uses

Code:
man cp
 
Old 03-04-2010, 12:09 AM   #22
Devcon
Member
 
Registered: Nov 2002
Posts: 35

Rep: Reputation: 16
Quote:
Originally Posted by DeNayGo View Post
I know this thread is getting kinda old, but there doesn't seem to be another _real_ solution, yet, so here's mine:

http://www.beatex.org/web/advancedcopy.html

It's a patch for the original GNU coreutils.

This does exactly what the creator of this thread had in mind. All you have to do is add -g to cp and you have one overall and one per file progress bar to entertain you while you're waiting
Wow. I've been looking for this kind of functionality for some time. I know rsync is a more robust alternative for heavy duty copies, but I consider rsync to be more for scripted operations. A '--progress-bar' option should be a stock option for cp. I compiled your source and copied the executable as 'acp'.

The only thing left is to develop effective resume options.

Thanks for the patch

Last edited by Devcon; 03-04-2010 at 12:12 AM.
 
Old 03-07-2010, 02:19 AM   #23
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,561

Rep: Reputation: 57
Quote:
Originally Posted by Devcon View Post
Wow. I've been looking for this kind of functionality for some time. I know rsync is a more robust alternative for heavy duty copies, but I consider rsync to be more for scripted operations. A '--progress-bar' option should be a stock option for cp. I compiled your source and copied the executable as 'acp'.

The only thing left is to develop effective resume options.

Thanks for the patch
rsync is bit buggy. Sometimes it hangs saying that configuration files are missing. beware. cp is more robust, by far.
 
0 members found this post helpful.
Old 03-07-2010, 05:20 PM   #24
Devcon
Member
 
Registered: Nov 2002
Posts: 35

Rep: Reputation: 16
I've never had problems with rsync, although it is all the more reason to push this patch. I've copied many gigs with advanced copy, and am yet to have serious problems. However, it seems the reported speed and time estimations can be a bit erratic.
 
Old 09-30-2010, 04:39 PM   #25
DanCard
LQ Newbie
 
Registered: Sep 2010
Posts: 3

Rep: Reputation: 0
Quote:
Originally Posted by DeNayGo View Post
I know this thread is getting kinda old, but there doesn't seem to be another _real_ solution, yet, so here's mine:

(removed: not allowed to quote an url)

It's a patch for the original GNU coreutils.

This does exactly what the creator of this thread had in mind. All you have to do is add -g to cp and you have one overall and one per file progress bar to entertain you while you're waiting
Have you submitted this as a patch to GNU coreutils?

Thanks,
Daniel
 
Old 11-19-2010, 07:22 AM   #26
loopingz
LQ Newbie
 
Registered: Nov 2010
Location: France
Distribution: Ubuntu 10.10
Posts: 6

Rep: Reputation: 0
This post is interesting.

I connect to my NAS in SSH. Then I have cp but no rsync. Is there a way to get rsync running on it or do I have to go a trhough cp and a script?

Thanks
 
Old 09-04-2011, 08:53 AM   #27
Muhlemmer
LQ Newbie
 
Registered: Sep 2011
Posts: 1

Rep: Reputation: Disabled
pv

I know this thread is quite old, but could not find the solution in a easy way, but combined solutions find elsewhere. Basically one could use the pv. Pv needs to be installed on you system though. (Package name is sys-apps/pv for gentoo). The following one-liner could be used:

Code:
cp <source> /proc/self/fd/1 | pv -s <size> -p -e -r | cp /proc/self/fd/0 <destination>
cp does not accept to write to standard output by default. It will fail if no input or output is given. So, in order to make it pipe to pv, we use /proc/self/fd/N. fd 0 represent standard input, fd 1 standard output and fd 2 standard error (we don't need that one for this purpose).

To get a process bar, we have to tell pv how much data it will read before we reach 100%. You can find the size of your file with:
Code:
du -h <source>
The size argument accepts K, M and G. Just like du -h gives you.

This will only work with a single file, so not for recursive copy of directories. You could use the rsync alternative for that.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cp with progress bar? Rotwang Linux - General 5 04-27-2005 07:49 PM
CLI progress bar for mv and cp command??? Lleb_KCir Linux - General 4 03-12-2005 09:12 PM
Progress bar image craigs1987 Fedora 0 05-27-2004 02:31 PM
cp: progress bar chii-chan Linux - General 2 10-30-2003 06:30 PM
Progress Bar zael Programming 3 10-01-2003 12:20 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration