LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-26-2010, 10:16 PM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Rep: Reputation: 76
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.

Last edited by stf92; 11-26-2010 at 10:17 PM.
 
Old 11-26-2010, 10:24 PM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
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.
 
Old 11-26-2010, 10:25 PM   #3
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,836
Blog Entries: 1

Rep: Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251Reputation: 1251
This should get you started:
http://www.linuxquestions.org/questi...command-96371/
 
Old 11-26-2010, 10:33 PM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
In bash version 4 and later parameter expansion can be used to uppercase a value using var=${var^^}
 
Old 11-26-2010, 10:46 PM   #5
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,623

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
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
 
Old 11-26-2010, 11:44 PM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
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
 
Old 11-27-2010, 12:43 AM   #7
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
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.

Last edited by stf92; 11-27-2010 at 12:44 AM.
 
Old 11-27-2010, 01:37 AM   #8
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Well that would be a fairly simple sed, but the choice is yours.
 
1 members found this post helpful.
  


Reply

Tags
filename, lowercase



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to separate lowercase and uppercase in my file cliffyao Linux - Newbie 4 06-14-2010 08:20 PM
Converting file names to uppercase mmahulo Linux - Newbie 5 12-19-2008 07:28 AM
External harddrive FAT32- VFAT options (uppercase to lowercase file name translation) pauquetb Linux - General 1 03-20-2004 12:52 PM
change file names to lowercase. david_wliu Linux - General 4 03-10-2003 01:17 PM
change file names to lowercase. david_wliu Programming 2 03-10-2003 12:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration