Search:  
Gentoo Wiki

TIP_lowercase_files_and_directories

This article is part of the Tips & Tricks series.
Terminals / Shells Network X Window System Portage System Filesystems Kernel Other
Warning: Only attempt to rename YOUR files. Linux is case sensitive and things may break if you run these programs/scripts as root or rename important system files.

Contents

Using convmv

A simple and reliable way to rename files and/or directories to lowercase is using convmv. To lowercase a file or directory use:

convmv --notest --lower SomeFileName

One can also use -r to make conversion recursive. When files which have to be converted have non-ASCII characters, it's required to enter the used charset of the filenames. Without knowledge of the used charset it would be impossible to reliably lowercase:

convmv --notest --lower -f utf-8 File_Ähh_with_Ümlauts

Using renamexm

A simple way to rename files and/or directories to lowercase is using renamxm from sys-apps/rename.

To lowercase a single file or directory use:

renamexm --lowcase name

To recursively lowercase a directory and its contents use:

renamexm --lowcase --recursive name

To recursively lowercase the contents of a directory, but not the directory itself, add a trailing slash to the directory name:

renamexm --lowcase --recursive name/

See renamexm --help and man renamexm for more options.

Using mmv

app-misc/mmv allows you to move, copy, and rename multiple files using wildcards and regular expressions.

To lowercase all files in the current directory, use:

mmv "*" "#l1"

To lowercase all files and directories in the current directory, use:

mmv -r "*" "#l1"

See man mmv for more usage options.

Bash script

Here is a nice little script from http://lists.suse.com/archive/suse-linux-e/2001-Jul/2593.html to lowercase-ify files and/or folders:

File: lowerit.sh
#!/bin/sh
#
# January 22, 1998
#
# Some ideas borrowed from the Tips-HOWTO. Modifications by BJ Goodwin
# <latency@radiolink.net>.
#
# Copyleft 1998
# All Beers Consumed.
#
if [ ! $1 ]; then
        echo "Not enough arguments. Try $0 -h for options."
        exit 1
fi
if [ $1 = "-f" -o $1 = "-d" -o $1 = "-a" -o $1 = "-h" ]; then
        :
   else
        echo "$0: Invalid argument. Try $0 -h for help."
        exit 1
fi
if [ $1 = "-f" ]; then
   for x in `ls`
     do
        if [ ! -f $x ]; then
                continue
        fi

     convert=`echo $x | tr '[A-Z]' '[a-z]'`

        if [ $convert != $x ]; then
                mv -i $x $convert
        fi
     done
   exit
fi
if [ $1 = "-d" ]; then
   for x in `ls`
     do
        if [ ! -d $x ]; then
                continue
        fi

     convert=`echo $x | tr '[A-Z]' '[a-z]'`

        if [ $convert != $x ]; then
                mv -i $x $convert
        fi
     done
   exit
fi
if [ $1 = "-a" ]; then
   for x in `ls`
     do
        if [ -f $x -a -d $x ]; then
                continue
        fi

     convert=`echo $x | tr '[A-Z]' '[a-z]'`

        if [ $convert != $x ]; then
                mv -i $x $convert
        fi
     done
   exit
fi
if [ $1 = "-h" ]; then
        echo "-----------------------------------------------------------"
        echo "lowercase v1.0 - Convert files or directories to lowercase."
        echo "-----------------------------------------------------------"
        echo "Usage: $0 <option>"
        echo
        echo "Options:"
        echo " -f = All files in current directory."
        echo " -d = All directories in current directory."
        echo " -a = All files AND directories in current directory."
        echo " -h = This help screen."
        echo
        echo "Notes: If a lowercase directory already exists that has the same"
        echo " name as the uppercase directory, the uppercase will be"
        echo " MOVED to the lowercase directory without confirmation."
        exit
fi 
Retrieved from "http://www.gentoo-wiki.info/TIP_lowercase_files_and_directories"

Last modified: Fri, 05 Sep 2008 23:09:00 +0000 Hits: 15,897