BASH – Filename Toggle Case

Disclaimer

The instructions/steps/scripts/methods given below worked for me running CentOS. It may very well work for you on other linux distributions, Red Hat-like or otherwise. Please note that if you decide to use these instructions on your machine, you are doing so entirely at your very own discretion and that neither this site, sgowtham.com, nor its author is responsible for any/all damage – intellectual or otherwise.

What is BASH?

BASH is a free software Unix shell written for the GNU Project. Its name is an acronym which stands for Bourne-again shell. The name is a pun on the name of the Bourne shell (sh), an early and important UNIX shell written by Stephen Bourne and distributed with Version 7 UNIX circa 1978, and the concept of being born again. BASH was created in 1987 by Brian Fox. In 1990 Chet Ramey became the primary maintainer. BASH is the default shell on most GNU/Linux systems as well as on Mac OS X and it can be run on most UNIX-like operating systems. It has also been ported to Microsoft Windows using the POSIX emulation provided by Cygwin, to MS-DOS by the DJGPP project and to Novell NetWare.

The Script

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#! /bin/bash
 
# BASH script to convert upper (lower) case filenames to lower (upper) case.
# Converts all files in a given directory, including any directory.
#
# Wed, 17 May 2006 22:09:15 -0400
 
# Uppercase to lowercase
for file in `ls *.*`;
do
  lfile=$(echo $file | tr [A-Z] [a-z])
  echo "  Converting ${file} to ${lfile} "
  mv ${file} ${lfile}
done
 
# Lowercase to Uppercase
# for file in `ls *.*`; 
# do
#   ufile=$(echo $file | tr [a-z] [A-Z])
#   echo "  Converting ${file} to ${ufile} "
#   mv ${file} ${ufile}
# done

Leave a Reply

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.