Created
June 2, 2020 23:42
-
-
Save krisgesling/afd6ce3d22d8c1bda1b9aaa1256122d6 to your computer and use it in GitHub Desktop.
Move a defined proportion of files from one folder to another. Particularly useful for directories with large numbers of files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
DIR_FROM=$1 | |
DIR_TO=$2 | |
PERCENTAGE=$3 | |
COUNTER=0 | |
for file in $DIR_FROM*; do | |
val=$RANDOM | |
# Max possible value is 32760 | |
((split=32760*$PERCENTAGE/100)) | |
if (($val < $split)); then | |
echo "Moving: $file" | |
mv "$file" $DIR_TO | |
((COUNTER=$COUNTER+1)) | |
fi | |
done | |
echo "Moved $COUNTER files." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment