LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Translating lowercase file names to uppercase. (https://www.linuxquestions.org/questions/linux-newbie-8/translating-lowercase-file-names-to-uppercase-846809/)

stf92 11-26-2010 10:16 PM

Translating lowercase file names to uppercase.
 
Kernel 2.6.21.5, Slackware 12.0

Hi:
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 10:24 PM

Something along these lines (untested)?
Code:

#! /bin/bash

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

# Rename files
while IFS= read -r -d '' file
do
    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 10:25 PM

This should get you started:
http://www.linuxquestions.org/questi...command-96371/

catkin 11-26-2010 10: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 10:46 PM

it looks like homework BUT with 655 posts - i dought it
lower2CAP.sh
Code:

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


grail 11-26-2010 11:44 PM

I am with catkin for bash 4:
Code:

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

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

stf92 11-27-2010 12: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
foo.html
foo_files/
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 01:37 AM

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


All times are GMT -5. The time now is 05:54 AM.