Aug 20, 2011
tom

How can I recursively change the case of files and folders under bash

Question

I have some files and folders that are all in uppercase that I want to rename to their lowercase equivalent. What would be the best way to go about doing this in bash on a Linux system?

As an example I might have:

.
|-- FOLDER0
|   |-- SUBFOLDERA
|   `-- SUBFOLDERB
`-- FOLDER1
    `-- AFILE.TXT

And I want to convert it to:

.
|-- folder0
|   |-- subfoldera
|   `-- subfolderb
`-- folder1
    `-- afile.txt

I can probably write a depth first recursive script to do this (depth first to ensure that files and subfolders are renamed before their parent folder), but I was wondering if there is a better way. rename might be useful, but it doesn’t seem to support recursion.

Answer

find . -depth -print0 | xargs -0 rename -n '$_ = lc $_'

Take out the -n flag once you’re sure that it’s doing what you want.

Related posts:

  1. Recursively rename files using find and sed
  2. Change ownership or permissions on only directories or files, recursively
  3. Finding/deleting top level folders not containing any files
  4. mount multiple folders with nfs4 on centos
  5. Change user permissions on files/directories where user = fred recursively

Leave a comment