Re: Updates on "mv", "cp" commands

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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
> http://www.brunobraga.net
> bruno.braga@xxxxxxxxx
> *******************************
> 
> "The future belongs to people who see possibilities before they become
> obvious!." -- Ted Levitt
> 
> 
> 
> 2009/11/1 Michal Nazarewicz <mina86@xxxxxxx>:
> > "BRAGA, Bruno" <bruno.braga@xxxxxxxxx> 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@xxxxxxxxxxxxxxx
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 
Renato 字. []'s, RCB.

Attachment: pgp8dZIrmwS2X.pgp
Description: PGP signature


[Index of Archives]     [Audio]     [Hams]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Samba]     [Fedora Users]

  Powered by Linux