user710818
user710818

Reputation: 24248

How to change case of file names recursive?

I need to set case of all files to lowercase:

directory11
       subdirectory11
             subdirectory21
                 File1
                 File2
                 ...
                 Filen
directory21
       subdirectory21
             subdirectory21
                 File1
                 File2
                 ...
                 Filen
..............................................


directory11
       subdirectory11
             subdirectory21
                 file1
                 file2
                 ...
                 filen
directory21
       subdirectory21
             subdirectory21
                 file1
                 file2
                 ...
                 filen
..............................................

Does it possible with linux command? Thanks.

Upvotes: 1

Views: 580

Answers (3)

another.anon.coward
another.anon.coward

Reputation: 11395

One of many possible options is using tr to change the case. Find all the files using find in the directory. Create the upper file name string using tr & use mv to rename. Something on these lines:

while read OLD_FILENAME
do
    NEW_FILENAME=`echo "$OLD_FILENAME"|tr [:upper:] [:lower:]`
    mv -v "$OLD_FILENAME" "$NEW_FILENAME"
done < <(find directory_name -type f)

Or if you want interactive mode for mv i.e ask for replacement confirmation use something on these lines:

(
IFS=$'\n'
for OLD_FILENAME in $(find directory_name -type f)
do
   NEW_FILENAME=`echo "$OLD_FILENAME"|tr [:upper:] [:lower:]`
   mv -vi "$OLD_FILENAME" "$NEW_FILENAME"
done
)

Hope this helps!

Upvotes: 1

Gilles Qu&#233;not
Gilles Qu&#233;not

Reputation: 185073

You should consider to using rename(1) command :

rename 'y/A-Z/a-z/' **

** mean recursive if you are using bash4 and globstar setting :

shopt -s globstar

Moreover, this is the perl version of rename. If you type

file $(readlink -f $(type -p rename))

and you see ELF, you have the wrong one, see prename

Upvotes: 1

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100175

You can do:

rename 'y/A-Z/a-z/' *

Upvotes: 1

Related Questions