Convert File Names To Alphabet Letters

2

Convert File Names To Alphabet Letters

For example , I have several image / photo files in a directory, and I want to pass these long names of their images into names designated by the letters of the alphabet

Before

IMG01-03082016.jpg

IMG02-03082016.jpg

IMG03-03082016.jpg

etc ...

Then

A.jpg

B.jpg

C.jpg

etc ...

    
asked by anonymous 21.08.2016 / 17:29

2 answers

1

Here is a tested solution to the problem:

#/bin/bash

n=0

alfabeto=$(echo {A..Z})

find . -maxdepth 1 -name '*.jpg' -type f  | while read imagem; do

    mv "${imagem}" "${alfabeto[n++]}.jpg"

done

exit 0

#fim-de-arquivo#
    
23.08.2016 / 16:08
1

The comment from JJoao and the Lacobus answer made me reach the shell-script :

 #!/bin/sh
 #
 # Por - Diego Henrique
 #
 # Programa - Renomear Arquivos Para Letras Do Alfabeto
 #
 # NOTA - Deve-se ter no máximo 26 Arquivos, alojado neste diretório 
 # Isso se dá ao número no qual corresponde as 26 Letras Alfabéticas 
 #
 n=0; LETRA=(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z);

 ls $HOME/*.png | while read IMG; do mv "$IMG" "${LETRA[n++]}.png"; 

 done
  

This is what worked perfectly on my Pinguin System - Damn Small Linux


About my own experience (errors / hits), I decided to leave this as an absolute answer.

    
28.08.2016 / 04:47