Created
November 6, 2010 16:51
-
-
Save walbon/665531 to your computer and use it in GitHub Desktop.
Organizador de fotos por data, separando-as por ano, mes e dia, e depois por md5sum o novo nome do arquivo.
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 | |
# | |
# Para arrumar suas fotos em um local seguro, faça um find da seguinte maneira | |
# ex: find fotos/ -type f -exec fotoArrumacao.sh {} pastaDestino/ \; | |
# | |
destino=$2 | |
imagem=$1 | |
# Testar a existência do exif para analisar o cabeçalho. | |
exif=`whereis exif|cut -d" " -f2` | |
if [ -e "$exif" ] | |
then | |
echo "Testando programas...\t(exif Ok)" | |
else | |
echo "Erro: Necessário \$exif " | |
exit | |
fi | |
echo Processing $imagem | |
if [ -e "$imagem" ] | |
then | |
tipo=`file "$imagem" | egrep -i JPEG | wc -l` | |
if [ "$tipo" -gt 0 ] | |
then | |
data=`exif "$imagem" |\ | |
egrep origina |\ | |
cut -d"|" -f2 |\ | |
cut -d" " -f1 |\ | |
sed -e "s/:/\//g"` | |
ano=`echo $data | cut -d"/" -f1` | |
mes=`echo $data | cut -d"/" -f2` | |
dia=`echo $data | cut -d"/" -f3` | |
nome=`md5sum "$imagem" | cut -d" " -f1` | |
echo "Criando pastas para armazenamento." | |
mkdir -p $destino/$ano/$mes/$dia # By Maurício(@mfoliveira) | |
echo "Copiando Imagem :cp "$imagem" $destino/$ano/$mes/$dia/$nome" | |
cp "$imagem" $destino/$ano/$mes/$dia/$nome | |
echo "$nome:$imagem" >> $destino/$ano/$mes/$dia/.nomes_antigos | |
echo "Limpar log" | |
cp $destino/$ano/$mes/$dia/.nomes_antigos $destino/$ano/$mes/$dia/.nomes_antigos_backup | |
cat $destino/$ano/$mes/$dia/.nomes_antigos_backup | \ | |
sort | \ | |
uniq > $destino/$ano/$mes/$dia/.nomes_antigos | |
rm $destino/$ano/$mes/$dia/.nomes_antigos_backup | |
else | |
echo -e "\tJPG não Válida: " $imagem | |
fi | |
else | |
echo "Arquivo não existe" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment