Gentoo Archives: gentoo-user

From: Alex Schuster <wonko@×××××××××.org>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Change the case of file names
Date: Mon, 02 Jul 2007 21:59:44
Message-Id: 200707022347.54400.wonko@wonkology.org
In Reply to: [gentoo-user] Change the case of file names by Mick
1 Mich writes:
2
3 > I backed up my wife's WinXP fs using K3B and I used default settings
4 > which unfortunately converted all file names to CAPITALS and shortened
5 > them to 8 characters maximum, just like DOS would do. Is there a clever
6 > way to change some of them back to lower case (in batches within given
7 > directorates) so that she doesn't have to do it manually one by one? I
8 > do not want to change the access times, only the filename case letters.
9
10 Create a script like this, name it lowercase.sh or something, and call it
11 with "lowercase file1 file2 dir1 dir2". I takes a list of files as
12 arguments (use * for all), and also works for directories.
13 So, "lowercase ." should convert all files and directories to lowercase.
14
15 Put the script into your $PATH, or precede it by its path, e.g. ./lowercase.
16 To test it before possible messing up (I just wrote this quickly) use
17 the -t option: lowercase -t /path/to/your/files
18
19
20 #!/bin/bash
21
22 # parse options (-t only)
23 while getopts "t" opt
24 do
25 case $opt in
26 t )
27 test=true
28 ;;
29 * )
30 exit 1
31 esac
32 done
33
34 shift $(( OPTIND-1 ))
35
36 # loop over arguments
37 while (( $# ))
38 do
39 file=$1
40 if [[ -d $file ]]
41 then
42 # call myself
43 $0 ${test:+-t} "$file"/*
44 elif [[ -f $file ]]
45 then
46 # conversion to lowercase
47 dir=$( dirname "$file" )
48 base=$( basename "$file" )
49 lower=$( echo "$base" | tr '[:upper:]' '[:lower:]' )
50 newfile=${dir:+$dir/}$lower
51 [[ $file -ef $newfile ]] ||
52 ${test:+echo} mv -v "$file" "$newfile"
53 else
54 echo "File not found: '$1'"
55 fi
56 shift
57 done
58
59
60 Alex
61 --
62 gentoo-user@g.o mailing list

Replies

Subject Author
Re: [gentoo-user] Change the case of file names Mick <michaelkintzios@×××××.com>