Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi All,
Could you please let me know if there is a way to run Unix commands like 'mv', 'cp' and 'compress' in parallel. I have a script to 'mv' or cp or 'compress' the file in serial by going in to a 'do loop'. But due to volume I really would like to accomplish the parallel 'mv' or 'cp' or 'compress'.
I greatly appreciate if you let me know a way to accomplish this. A sample script will be of a great help!
Thank you very much for your time and help!
Have a great day!Regards,
Sam.

Put the compress in background. Example:
#!/bin/ksh
for file in *
do
if [[ ! -d $file ]]
then
cp $file /newdirectory/$file
compress /newdirectory/$file &
fi
doneWith a little imagination, you can add all sorts of error checking and counters to the script.

This can result in many compress'es running at once, slowing system response and PO'ing users.
How large are the files? Are the mv/cp to a different file system?

So use 2 loops. One that puts a fixed number of processes in background and then waits until they finish before getting the next group. This is not difficult. He just asked how to do it and background processes are the only way this will be accomplished.

of course, of course.
However, if the files are not too large and they are not being moved to a different file system, the time savings might be
teeny.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |