title: linux bash - move x percentage of files from each folder
body: <p>I have the following folder structure:</p>
  
  <pre><code>maindir
  |-sub1
  |-sub2
  |-sub...
  |-sub1000
  </code></pre>
  
  <p>What I want to achieve is to move from each sub directory eg. 10% of the files which each folder contain into a new folder maindir2 with the same structure:</p>
  
  <pre><code>maindir2
  |-sub1
  |-sub2
  |-sub...
  |-sub1000
  </code></pre>
  
  <p>Assuming in the sub directories from maindir is the following amount of files (numbers in bracelets):</p>
  
  <pre><code>maindir
  |-sub1 (10)
  |-sub2 (100)
  |-sub...
  |-sub1000 (50)
  </code></pre>
  
  <p>I would like to have as output the following in maindir2:</p>
  
  <pre><code>maindir
  |-sub1 (1)
  |-sub2 (10)
  |-sub...
  |-sub1000 (5)
  </code></pre>
  
  <p>and in maindir:</p>
  
  <pre><code>maindir
  |-sub1 (99)
  |-sub2 (90)
  |-sub...
  |-sub1000 (45)
  </code></pre>
  
  <p>Please let me know how this is possible with a bash command preferably.</p>