Shell Script To Rename File Name To Lowercase

in Categories File-management last updated September 16, 2008

This script use tr command to convert uppercase file name to a lowercase file name. The tr utility copies the given input to produced the output with substitution or deletion of selected characters. tr abbreviated as translate or transliterate. It takes as parameters two sets of characters, and replaces occurrences of the characters in the first set with the corresponding elements from the other set i.e. it is used to translate characters.

# Write a shell script that changes the name of the file passed as argument
# to lowercase.
# -------------------------------------------------------------------------
# Copyright (c) 2003 nixCraft project <>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit for more information.
# -------------------------------------------------------------------------
if [ $# -eq 0 ]
	echo "$(basename $0) file"
	exit 1
if [ ! $file ]
	echo "$file not a file"
	exit 2
lowercase=$(echo $file | tr '[A-Z]' '[a-z]'])
if [ -f $lowercase ]
	echo "Error - File already exists!"
	exit 3
# change file name
/bin/mv $file $lowercase

Share this on:

Leave a Comment