LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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, 11:16 PM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,289

Rep: Reputation: 50
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 11:17 PM.
 
Old 11-26-2010, 11:24 PM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,563
Blog Entries: 29

Rep: Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179
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, 11:25 PM   #3
sycamorex
LQ Veteran
 
Registered: Nov 2005
Location: London
Distribution: Slackware64-current
Posts: 5,613
Blog Entries: 1

Rep: Reputation: 1052Reputation: 1052Reputation: 1052Reputation: 1052Reputation: 1052Reputation: 1052Reputation: 1052Reputation: 1052
This should get you started:
http://www.linuxquestions.org/questi...command-96371/
 
Old 11-26-2010, 11:33 PM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,563
Blog Entries: 29

Rep: Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179Reputation: 1179
In bash version 4 and later parameter expansion can be used to uppercase a value using var=${var^^}
 
Old 11-26-2010, 11:46 PM   #5
John VV
Guru
 
Registered: Aug 2005
Posts: 13,531

Rep: Reputation: 1807Reputation: 1807Reputation: 1807Reputation: 1807Reputation: 1807Reputation: 1807Reputation: 1807Reputation: 1807Reputation: 1807Reputation: 1807Reputation: 1807
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-27-2010, 12:44 AM   #6
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,698

Rep: Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988
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, 01:43 AM   #7
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,289

Original Poster
Rep: Reputation: 50
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 01:44 AM.
 
Old 11-27-2010, 02:37 AM   #8
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,698

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


Reply

Tags
filename, lowercase


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 09:20 PM
Converting file names to uppercase mmahulo Linux - Newbie 5 12-19-2008 08:28 AM
External harddrive FAT32- VFAT options (uppercase to lowercase file name translation) pauquetb Linux - General 1 03-20-2004 01:52 PM
change file names to lowercase. david_wliu Linux - General 4 03-10-2003 02:17 PM
change file names to lowercase. david_wliu Programming 2 03-10-2003 01:59 PM


All times are GMT -5. The time now is 11:56 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration