-   Linux - Newbie (
-   -   Translating lowercase file names to uppercase. (

stf92 11-26-2010 11:16 PM

Translating lowercase file names to uppercase.
Kernel, Slackware 12.0

As a result of having mixed files from different filesystems, I have, in directory foo/, files with filenames in uppercase and files with filenames in lowercase. If I want to convert them to all uppercase how do I do it? Consider this will be later recorded into optical discs. Regards.

catkin 11-26-2010 11:24 PM

Something along these lines (untested)?

#! /bin/bash

# Configure script environment
export PATH=/usr/bin:/bin
set -o nounset
unalias -a

# Rename files
while IFS= read -r -d '' file
    file_upper=$( echo -n "$file" | /usr/bin/tr '[:upper:]' '[:lower:]' )
    echo mv "$file" "$file_upper"
done < <(find foo -type f -print0)

If it is creating the mv commands you want, remove the echo.

sycamorex 11-26-2010 11:25 PM

This should get you started:

catkin 11-26-2010 11:33 PM

In bash version 4 and later parameter expansion can be used to uppercase a value using var=${var^^}

John VV 11-26-2010 11:46 PM

it looks like homework BUT with 655 posts - i dought it

for i in *; do mv "$i" "$(echo $i | tr '[a-z]' '[A-Z]')"; done

grail 11-27-2010 12:44 AM

I am with catkin for bash 4:

for x in *;do mv "$x" "${x^^}";done
Or if you have access to rename:

rename -n 's/(.*)/\U$1/' *
Remove -n to make it happen

stf92 11-27-2010 01:43 AM

Thank you guys, but I've just reconsidered and have seen the problem is unsolvable. Many of the files are of the type
If I rename any of the files in foo_files, the HTML page will lack something. Infact, foo.html contains the names of all files in foo_files/. Renaming any of them, means to edit foo.html and change the name there too. Sorry for the inconvenience.

grail 11-27-2010 02:37 AM

Well that would be a fairly simple sed, but the choice is yours.

All times are GMT -5. The time now is 03:50 AM.