LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 01-24-2006, 09:10 AM   #1
edwardsiow
LQ Newbie
 
Registered: Jan 2006
Posts: 11

Rep: Reputation: 0
cp progress bar


Hi,
I have to copy large files from a CD to the hard disk.

I want to use a progress bar to display the status of
copying the files.

Any one has ideas about implementing this in shell script.
 
Old 01-24-2006, 09:19 AM   #2
hellodio
Member
 
Registered: Oct 2005
Posts: 33

Rep: Reputation: 15
Quote:
Originally Posted by edwardsiow
Hi,
I have to copy large files from a CD to the hard disk.

I want to use a progress bar to display the status of
copying the files.

Any one has ideas about implementing this in shell script.
One may use a GUI based file manager for that. I.e. Nautilus (Gnome) or XFE (http://roland65.free.fr/xfe/), etc.
 
Old 01-24-2006, 09:34 AM   #3
edwardsiow
LQ Newbie
 
Registered: Jan 2006
Posts: 11

Original Poster
Rep: Reputation: 0
thanks for your advice

i have found a sample code in this forum

Code:
#!/bin/bash

files=`ls -l | wc -l`
copied=1
clear
echo "                     Please wait, copy in progress"
while [ $files -ge $copied ] ;do
   pct=$((100 * copied / $files))
   copied=$((copied + 1))
   echo -en ".$pct%\b\b\b"  ## you can use # or anything instead of dots 
   sleep 1
done
  echo -e "\n"
  echo "                     The operation is complete"
  echo -e "\n"
but i don't know how to modify this code so that i can use it to copy large files from a CD to the hard disk and at the same time showing the progress bar.

anyone can help me, please...
 
Old 01-24-2006, 10:13 AM   #4
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
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
 
Old 01-24-2006, 10:44 AM   #5
edwardsiow
LQ Newbie
 
Registered: Jan 2006
Posts: 11

Original Poster
Rep: Reputation: 0
thanks for your resources..

i am sorry to tell that i am newbie and not so understand the above sample codes..

maybe you will ask me to go back study hard..but i really need to solve this problem urgent and dont have time for me to study. believe or not depend on you...

below code is easy for me to understand:
Code:
#!/bin/bash
umount /mnt/cdrom
mount /mnt/cdrom
mkdir ~/Desktop/CDcontents
cp -R /mnt/cdrom/  ~/Desktop/CDcontents/
eject /mnt/cdrom
but i don't know how to modify n put into the sample codes you provided above..if you don't mind, please give me guidiance..

thanks again..
 
Old 01-24-2006, 12:28 PM   #6
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 61
Example: ./test original_file destination_file

This part is the name of my script ------> ./test
To use ./test , I made it execute with the command: chmod +x test
or you could use the method of : sh test

original_file ---------> Is actually a directory in your case.
that is /mnt/cdrom

destination_file --------> Is actually a directory in your case.
~/Desktop/CDcontents/


So, it might look like this...
./test /mnt/cdrom ~/Desktop/CDcontents/

Because it's a directory, you may need to play with the copy statement. Look into man cp for that. Maybe something like.....
cp -R $1 $2 &
 
Old 01-24-2006, 12:31 PM   #7
edwardsiow
LQ Newbie
 
Registered: Jan 2006
Posts: 11

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by homey
Example: ./test original_file destination_file

This part is the name of my script ------> ./test
To use ./test , I made it execute with the command: chmod +x test
or you could use the method of : sh test

original_file ---------> Is actually a directory in your case.
that is /mnt/cdrom

destination_file --------> Is actually a directory in your case.
~/Desktop/CDcontents/


So, it might look like this...
./test /mnt/cdrom ~/Desktop/CDcontents/

Because it's a directory, you may need to play with the copy statement. Look into man cp for that. Maybe something like.....
cp -R $1 $2 &
wow~~thanks a lot!!! let's me try first...i am appreciate your help...
 
Old 01-24-2006, 02:09 PM   #8
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Quote:
Originally Posted by edwardsiow
Hi,
I have to copy large files from a CD to the hard disk.

I want to use a progress bar to display the status of
copying the files.

Any one has ideas about implementing this in shell script.
Here is something that look similar, "catenate with progress":

http://www.ex-parrot.com/~chris/software.html
 
Old 09-02-2006, 05:03 PM   #9
keyvez
LQ Newbie
 
Registered: Aug 2006
Posts: 1

Rep: Reputation: 0
Cool

You can use MC (Midnight Commander). The worlds best console file manager.

To install mc on ubuntu, enable the universe repository from /etc/apt/sources.list by removing the # before the universe repository.

Then simply say
sudo apt-get install mc

and then type mc on the command line to open up the colsole app.
 
Old 03-24-2008, 10:58 AM   #10
mk6032
LQ Newbie
 
Registered: Oct 2004
Location: Chattanooga, TN
Distribution: rhel, ubuntu, opensuse
Posts: 13

Rep: Reputation: 0
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
This works well for file->file, but file->directory will result in an endless loop you have to ctrl-c out of:


Code:
[mk6032@linuxquestions]# cp movie.avi /srv/nfs/media/video/
Preparing to copy
/root/cp_progress.sh: line 16: /srv/nfs/media/video/: Is a directory
###########################################################  0%
[mk6032@linuxquestions]#
It needs to run a check on the destination first:
if [ -d $2 ] then ....
 
Old 11-07-2008, 03:55 AM   #11
michelemase
LQ Newbie
 
Registered: Nov 2008
Posts: 3

Rep: Reputation: 0
Thumbs up code improved

Here it's a little improvement of the script; it should work if the second field is a directory now.


Code:
--- cp_p.org	2008-11-07 10:47:25.934417154 +0100
+++ cp_p2	2008-11-07 10:40:17.674417698 +0100
@@ -8,13 +8,17 @@
 
 test $# == 2 || usage
 orig_size=$(stat -c %s $1)
+if [ -d "$2" ]
+then d="$2/$1"
+else d="$2"
+fi
+>"$d"
 
->$2
 dest_size=0
-cp -f $1 $2 &
+cp -f $1 "$d" &
 
 while [ $orig_size -gt $dest_size ] ; do
-   dest_size=$(stat -c %s $2)
+   dest_size=$(stat -c %s "$d")
    pct=$((( 69 * $dest_size ) / $orig_size ))
 
     echo -en "\r["
 
Old 03-09-2009, 02:58 PM   #12
adam2508
LQ Newbie
 
Registered: Mar 2009
Location: Downey, ca
Distribution: Debian
Posts: 9

Rep: Reputation: 0
what does:
>"$d"

does?
I understand everything else, i just dont know what ">$d" by itself does.
can someone explain? thank you
 
Old 03-10-2009, 03:26 AM   #13
michelemase
LQ Newbie
 
Registered: Nov 2008
Posts: 3

Rep: Reputation: 0
>d$

It should create an empty destination file; the script also works without it.
Try it!
 
Old 04-28-2009, 11:27 AM   #14
nonzenze
LQ Newbie
 
Registered: Apr 2009
Posts: 1

Rep: Reputation: 1
rsync -rv <src> <dst> --progress:

-r for recursive (if you want to copy entire directories)
src for the source file (or wildcards)
dst for the destination
--progress to show a progress bar

Honestly, rsync is only a little slower than cp for local copies and is so much better featured.
 
1 members found this post helpful.
Old 05-07-2009, 02:46 PM   #15
treehead
LQ Newbie
 
Registered: Oct 2004
Location: USA
Distribution: Slackware
Posts: 18

Rep: Reputation: 1
pv

You can also look at pv (Pipe Viewer), but honestly, for the specific solution you're looking for--copying a tree of files off a CD-ROM with a progress bar--rsync is the best solution, as nonzenze said.

cRaig
 
  


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 03:59 PM.

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