Created
June 22, 2015 07:41
-
-
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
This file contains 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 | |
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