About

Script Categories

Shell Script To Rename File Name To Lowercase

Posted in File-management

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.

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

Download - Email this to a friend - Printable version

Is your site working? Monitor Your Web Site 24/7. Get SMS alerts on server downtime! Free 30-day trial including 20 SMS!

Related Other Helpful Shell Scripts:

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Tags: , , , , , , , , , ~ Last updated on: September 16, 2008