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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
|
01-24-2006, 09:10 AM
|
#1
|
|
LQ Newbie
Registered: Jan 2006
Posts: 11
Rep:
|
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.
|
|
|
|
01-24-2006, 09:19 AM
|
#2
|
|
Member
Registered: Oct 2005
Posts: 33
Rep:
|
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.
|
|
|
|
01-24-2006, 09:34 AM
|
#3
|
|
LQ Newbie
Registered: Jan 2006
Posts: 11
Original Poster
Rep:
|
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...
|
|
|
|
01-24-2006, 10:13 AM
|
#4
|
|
Senior Member
Registered: Oct 2003
Posts: 3,057
Rep:
|
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
|
|
|
|
01-24-2006, 10:44 AM
|
#5
|
|
LQ Newbie
Registered: Jan 2006
Posts: 11
Original Poster
Rep:
|
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..
|
|
|
|
01-24-2006, 12:28 PM
|
#6
|
|
Senior Member
Registered: Oct 2003
Posts: 3,057
Rep:
|
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 &
|
|
|
|
01-24-2006, 12:31 PM
|
#7
|
|
LQ Newbie
Registered: Jan 2006
Posts: 11
Original Poster
Rep:
|
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...
|
|
|
|
01-24-2006, 02:09 PM
|
#8
|
|
Moderator
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Ubuntu, OL
Posts: 9,311
|
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
|
|
|
|
09-02-2006, 05:03 PM
|
#9
|
|
LQ Newbie
Registered: Aug 2006
Posts: 1
Rep:
|
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.
|
|
|
|
03-24-2008, 10:58 AM
|
#10
|
|
LQ Newbie
Registered: Oct 2004
Location: Chattanooga, TN
Distribution: rhel, ubuntu, opensuse
Posts: 13
Rep:
|
Quote:
Originally Posted by homey
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 ....
|
|
|
|
11-07-2008, 03:55 AM
|
#11
|
|
LQ Newbie
Registered: Nov 2008
Posts: 2
Rep:
|
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["
|
|
|
|
03-09-2009, 02:58 PM
|
#12
|
|
LQ Newbie
Registered: Mar 2009
Location: Downey, ca
Distribution: Debian
Posts: 9
Rep:
|
what does:
>"$d"
does?
I understand everything else, i just dont know what ">$d" by itself does.
can someone explain?  thank you
|
|
|
|
03-10-2009, 03:26 AM
|
#13
|
|
LQ Newbie
Registered: Nov 2008
Posts: 2
Rep:
|
>d$
It should create an empty destination file; the script also works without it.
Try it!
|
|
|
|
04-28-2009, 11:27 AM
|
#14
|
|
LQ Newbie
Registered: Apr 2009
Posts: 1
Rep:
|
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.
|
05-07-2009, 02:46 PM
|
#15
|
|
LQ Newbie
Registered: Oct 2004
Location: USA
Distribution: Slackware
Posts: 18
Rep:
|
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
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 09:06 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|