Shell script to rename to lowercase files and directories


In the GNU/Linux world, it is common to use lowercase characters to identify files and directories, to illustrate the above we show the DIRs that are found under the /etc/apache2 DIR on Debian GNU/Linux

├── conf-available
├── conf-enabled
├── mods-available
├── mods-enabled
├── sites-available
└── sites-enabled

so if you have one or several DIRs in uppercase or lowercase and uppercase at the same time and for uniformity want to all be lowercase then you can rely on the following script.

#!/usr/bin/env bash
# GNU shell script para renombrar a minúscula ficheros y
# directorios
# ---------------------------------------------------------------
# Copyright (c) 2009 flossblog <>
# Este script es liberado bajos los téminos de la GNU GPL
# version 2.0 o superior
# --------------------------------------------------------------
# Uso:
# El script recibe como parámetro el nombre un fichero o
# directorio, para un directorio la operación se hará de
# forma recursiva
#  -------------------------------------------------------------
# Última actualización: 10 de junio del 2009

find "$1" -depth -print0 | while read -d $'\0' file; do
        NEWBASENAME=$(basename "$file" | tr [:upper:] [:lower:])
        NEWFILENAME=$(dirname "$file")/$NEWBASENAME
        mv -f "$file" "$NEWFILENAME" 2> /dev/null

To use the script download here

Set execute permissions
chmod a+x
Run the script
./ nombre-del-fichero

Further readings

  • man find
  • man tr

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.