Umashankar P M
Umashankar P M

Reputation: 13

How to run md5sum parallely on some 10 files named test1...test10 in the directory

I'm able to run serially but unable to run it parallely. My code is as below:

#!/bin/bash
while :
do
  for i in `find ~/Mainstore-1/ -maxdepth 1 -type f`
  do
    md5sum $i
  done
  sleep 1
done

Upvotes: 1

Views: 60

Answers (1)

hek2mgl
hek2mgl

Reputation: 158250

This should do:

find ~/Mainstore-1/ -maxdepth 1 -type f -print0 | while read -d '' -r file ; do
    # launch md5sum in background using `&`
    md5sum "$file" &
done

# Wait for workers to finish
wait

Upvotes: 2

Related Questions