Skip to content

Instantly share code, notes, and snippets.

@WillCQ97
Created February 5, 2021 13:03
Show Gist options
  • Save WillCQ97/3a624ce3eb51deaa7225c8b7e227746c to your computer and use it in GitHub Desktop.
Save WillCQ97/3a624ce3eb51deaa7225c8b7e227746c to your computer and use it in GitHub Desktop.
Move arquivos aleatóriamente para pastas numeradas, de acordo com o máximo de arquivos definidos para cada pasta.
#!/bin/bash
# Autor: willcq
# Cria diretórios e randomicamente move arquivos para ele.
CONT=0
VALOR=1
MAX_ARQ=20
ls | sort -R | while read -r file ; do
if [ $CONT -eq 0 ]
then
echo "Criando o diretório dir_$VALOR"
mkdir dir_$VALOR
fi
printf 'Movendo arquivo '"'%s'"'\n' "$file"
mv "$file" dir_$VALOR
if [ $CONT -eq $MAX_ARQ ]
then
CONT=0
VALOR=$[ $VALOR + 1 ]
else
CONT=$[ $CONT + 1 ]
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment