Skip to content

Instantly share code, notes, and snippets.

@angrychimp
Last active January 12, 2017 23:18
Show Gist options
  • Select an option

  • Save angrychimp/592544a8e7fb2bfbc40918dec281f871 to your computer and use it in GitHub Desktop.

Select an option

Save angrychimp/592544a8e7fb2bfbc40918dec281f871 to your computer and use it in GitHub Desktop.
Using random variables in a subshell
# As an example, how to randomly distribute files to a collection of folders
find source/ -type f -print0 | \
xargs -r0 -P 10 -I{} sh -c "
folders=($(ls targets/))
mv --target-directory=targets/\${folders[\$(expr \$RANDOM % \${#folders[@]})]}/
"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment