linux-console.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "BRAGA, Bruno" <bruno.braga@gmail.com>
To: linux-console@vger.kernel.org
Subject: Updates on "mv", "cp" commands
Date: Mon, 2 Nov 2009 16:39:50 +0900	[thread overview]
Message-ID: <86ca47940911012339q1b74231bm37de37c64d4fbd82@mail.gmail.com> (raw)
In-Reply-To: <86ca47940911012308m391bada5n4e62a089e427812b@mail.gmail.com>

Hi Renato,

thanks for the feedback.

In deed, I found some solutions such as wrapper scripts (the simplest
I saw using pv), and the aliases using rsync. For now, I will just
stick with the rsync aliases for simplicity.

pv solution:
pv big_file.tgz > /some_dir/sub_dir/big_file.tgz

aliases solution: (place on ~/.bashrc)
alias rscp=’rsync -aP –no-whole-file –inplace’
alias rsmv=’rscp –remove-source-files’

strace solution:

#!/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
}

sources:
http://www.debianadmin.com/pv-pipe-viewer-shell-pipeline-element-to-meter-data-passing-through.html
http://chris-lamb.co.uk/2008/01/24/can-you-get-cp-to-give-a-progress-bar-like-wget/

I placed this question under the GNU Coreutils mailing list, and got
lots of feedback too.

The discussion seems to be long, and getting kinda philosophic as
well. Let's see where this goes.
Here is another thread (old one) talking more about this:
https://bugzilla.redhat.com/show_bug.cgi?id=237553

thank you all for the help.

Bruno

On Mon, Nov 2, 2009 at 2:26 PM, Renato Callado Borges
<renato.oferenda@gmail.com> wrote:
>
> Hi Bruno!
>
> Wouldn't you prefer to build something on top of cp and mv, like a wrapper script? I did a sketch for such a wrapper for cp, tell me what you think.
>
> #!/bin/bash
>
> if [ ! -n "$2" ]; then
>    echo "Usage: $0 input_file output_file"
> fi
>
> LS_ALIAS=`alias | grep "ls='" | cut -d "'" -f 2`
> if [ -n "$LS_ALIAS" ]; then
>    unalias ls
> fi
>
> SIZE1=`ls -l "$1" | cut -d " " -f 5`
> cp "$1" "$2" &
> sleep 1
> echo -n "Copying: $1 -> $2 ["
> tput sc
> SIZE2=`ls -l "$2" | cut -d " " -f 5`
> while [ $SIZE2 -lt $SIZE1 ]; do
>    PERCENTAGE=`echo "a=$SIZE2/$SIZE1;100*a" | bc -l | cut -d "." -f 1`
>    tput rc
>    echo -n "$PERCENTAGE%]"
>    sleep 1
>    SIZE2=`ls -l $2 | cut -d " " -f 5`
> done
> echo " Done."
>
> if [ -n "$LS_ALIAS" ]; then
>    alias ls="$LS_ALIAS"
> fi
>
> Be careful: this script might fail if cp has to overwrite files, and there are race conditions (that's the reason for the sleep outside the while loop).
>
> Cheers,
> Renato.
>
> On Sun, Nov 01, 2009 at 08:47:21PM +0900, BRAGA, Bruno wrote:
> > Thanks for the reply Michal.
> >
> > I will look into that (I found the source in GNU's source code, but I
> > am still kinda lost on to whom should I ask stuff, lol). i will let
> > you know if/when I get things done with the team there.
> >
> > Cheers,
> >
> > Braga, Bruno
> >
> >
> >
> > 2009/11/1 Michal Nazarewicz <mina86@tlen.pl>:
> > > "BRAGA, Bruno" <bruno.braga@gmail.com> writes:
> > >> I don't know if that's the place to post this question, but I am sure
> > >> someone here will be able to give me hints on how to proceed.
> > >>
> > >> I would like to propose and patch improvements on the "mv" (move) and
> > >> "cp" (copy) commands, by adding options for progress information.
> > >
> > > That's something I was wondering about some time ago myself.
> > >
> > >> The idea is that any GUI actions already do it graphically, and other
> > >> CLI applications, such as "rsync", have this as an extended option
> > >> "--progress". This is handy for large files processing, for instance.
> > >>
> > >> I looked for the code in the kernel source but I did not find any. I
> > >> could find some sources on the GNU OS, but I am not sure if that's the
> > >> right place (probably not).
> > >
> > > You won't find any sources of cp or mv in Linux source code because cp
> > > and mv commands are user space and as such they are not part of Linux
> > > per se.
> > >
> > > If you are using some kind of GNU/Linux distribution the place to look
> > > is GNU coreutils package.  Consult gnu.org webpage for it's source code
> > > and information how to submit patches.
> > >
> > > --
> > > Best regards,                                         _     _
> > >  .o. | Liege of Serenly Enlightened Majesty of      o' \,=./ `o
> > >  ..o | Computer Science,  Michal "mina86" Nazarewicz   (o o)
> > >  ooo +--<mina86*tlen.pl>--<jid:mina86*jabber.org>--ooO--(_)--Ooo--
> > >
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-console" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
> --
> Renato 字. []'s, RCB.
--
To unsubscribe from this list: send the line "unsubscribe linux-console" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2009-11-02  7:39 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <86ca47940910310550s87a6140s377a3d752979037@mail.gmail.com>
2009-11-01  0:30 ` Updates on "mv", "cp" commands BRAGA, Bruno
2009-11-01  8:11   ` Michal Nazarewicz
2009-11-01 11:47     ` BRAGA, Bruno
2009-11-02  5:26       ` Renato Callado Borges
     [not found]         ` <86ca47940911012308m391bada5n4e62a089e427812b@mail.gmail.com>
2009-11-02  7:39           ` BRAGA, Bruno [this message]
2009-11-01 12:20   ` renato.oferenda
2009-11-01 12:51     ` BRAGA, Bruno
2009-11-01 13:01       ` renato.oferenda

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86ca47940911012339q1b74231bm37de37c64d4fbd82@mail.gmail.com \
    --to=bruno.braga@gmail.com \
    --cc=linux-console@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).