Skip to content

Instantly share code, notes, and snippets.

View angrychimp's full-sized avatar

Randall Kahler angrychimp

View GitHub Profile
# Dumps all files into the same folder
folders=($(ls targets/))
find source/ -type f -print0 | \
xargs -r0 -P 10 -I{} \
mv --target-directory=targets/${folders[$(expr $RANDOM % ${#folders[@]})]}/
@angrychimp
angrychimp / random-dist.sh
Last active January 12, 2017 23:18
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[@]})]}/
"