Skip to content

Instantly share code, notes, and snippets.

@vifito
Created June 22, 2015 07:41
Show Gist options
  • Save vifito/2de0dfb901d5521f1b0e to your computer and use it in GitHub Desktop.
Save vifito/2de0dfb901d5521f1b0e to your computer and use it in GitHub Desktop.
Recorrer ficheiros dun directorio, renomealos a letras minúsculas e poñerlles un prefixo numérico
#!/bin/bash
COUNTER=0
FILTER=".sql"
FORMAT="%03d-%s"
# Iterar polos ficheiros do directorio actual
for i in *; do
# Verificar se hai que procesar o ficheiro, se cumpre o filtro
if [[ $i =~ $FILTER ]]; then
# Pasar o nome a minúsculas
BASENAME=`echo $i | tr [:upper:] [:lower:]`
COUNTER=`expr $COUNTER + 1`
echo -n "$i "
mv $i `printf $FORMAT $COUNTER $BASENAME`
echo " -> $_"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment