Skip to content

Instantly share code, notes, and snippets.

@iBet7o
Created January 19, 2015 01:01
Show Gist options
  • Save iBet7o/31f2ec660d214d7e389a to your computer and use it in GitHub Desktop.
Save iBet7o/31f2ec660d214d7e389a to your computer and use it in GitHub Desktop.
Script bash para renombrar directorios y archivos

Dependencias

  • Descargar archivo flash.sh.
  • Descargar archivo rename.sh que se encuentra mas abajo.

Instalación

Modificar los permisos del archivo rename.sh

chmod +x vhost.sh

Tabla de caracteres a remplazar

Carácter Remplazo
á a
é e
í i
ó o
ú u
Á A
É E
Í I
Ó O
Ú U
ñ n
Ñ N
[:space:] _

Forma de uso

Ejecutar el archivo rename.sh e ingresar la ruta para renombrar los archivos.

./rename.sh
Path to rename: /home/ibet7o/bash/rename/test
The process is complete.
File log /home/ibet7o/bash/rename/log.txt
#! /bin/bash
source flash.sh
# Variables
# ------------------------------------------------------------------------------
pathLog=`echo $(pwd)/log.txt`
echo -n "Path to rename: "
read path
if [ ! -d $path ]
then
flashError "The ${path} path does not exist"
exit
fi
baseDir=`basename $path`
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for item in `find ${path} | sort -r`
do
dirname=`dirname $item`
basename=`basename $item | sed "y/áéíóúÁÉÍÓÚñÑ/aeiouAEIOUnN/" `
basename=`echo -n "${basename// /_}"`
if [ "$baseDir" != "$basename" ]
then
path="$dirname/$basename"
if [ "$item" != "$path" ]
then
echo "mv $item $path" >> $pathLog
mv $item $path
fi
fi
done
IFS=$SAVEIFS
flashSuccess "The process is complete."
flashSuccess "File log $pathLog"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment