sort files in mulidirectory

I want to move files in a 12 directories.
Target is to move for example 30 files into directory “cpu1 cpu2 … cpu12”

i found already this:

#!/bin/bash

# outnum generates the name of the output directory
outnum=1
# n is the number of files we have moved
n=0

# Go through all JPG files in the current directory
for f in * ; do
   # Create new output directory if first of new batch of 2
   if  $n -eq 0 ]; then
      outdir=cpu$outnum
      mkdir $outdir
      ((outnum++))
   fi
   # Move the file to the new subdirectory
   mv "$f" "$outdir"

   # Count how many we have moved to there
   ((n++))

   # Start a new output directory if we have sent 2
    $n -eq 2 ] && n=0
done

That makes 2 files / dir
but i want to stop with max 12 dirs.
so making 12 dirs and move the files over this 12 dirs.

target for al this, to execute 12 times command because i have 12 cores :slight_smile:
Who can help me further?

If all source files are in a single directory, all operations will be serialized on this directory anyway. And this is not CPU intensive in any case, so you won’t see a difference.

i did a test

  • the job was 10% cpu and was done in 83 sec (all files in one dir)

  • if i load 12 times (100% cpu) the same execute on 12 dirs it was done in 23 sec.

(the cpu is intel i7 5820K)