LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-27-2005, 06:38 PM   #1
cubax
Member
 
Registered: Nov 2004
Posts: 34

Rep: Reputation: 15
lowercase recursively


Hello, I would need a script that automatically reads recursively in folders changing file names and folder names to lowercase.
I found "tr" command but it seems that it works with one file at once.

Is there something like a shell command, a perl script... ?

Thanks.
 
Old 05-27-2005, 07:04 PM   #2
mrcheeks
Senior Member
 
Registered: Mar 2004
Location: far enough
Distribution: OS X 10.6.7
Posts: 1,690

Rep: Reputation: 52
Assuming you are using bash, try
Code:
for i in .; do mv "$i" `echo $i | tr '[A-Z]' '[a-z]'`; done
 
Old 05-28-2005, 03:38 AM   #3
cubax
Member
 
Registered: Nov 2004
Posts: 34

Original Poster
Rep: Reputation: 15
I'm not a bash specialist but...
Am I wrong or your script cannot go down to "unlimited" subfolders?
My need is to start from a defined folder and lowercase all the files and folders below the starting one. Even with many "sublevels".

Thanks for your answer
 
Old 05-28-2005, 04:03 AM   #4
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 53
Quote:
Originally posted by cubax
I'm not a bash specialist but...
Am I wrong or your script cannot go down to "unlimited" subfolders?
My need is to start from a defined folder and lowercase all the files and folders below the starting one. Even with many "sublevels".

Thanks for your answer
That's easy to fix.
instead of
Code:
for i in .;
use
Code:
for i in `find .`;
 
Old 05-29-2005, 06:23 AM   #5
cubax
Member
 
Registered: Nov 2004
Posts: 34

Original Poster
Rep: Reputation: 15
Ok, I tried it but there is some problem...
It displays tons of errors like:
- Impossible to move the directory (dirName) in a subfolder of itself
- Impossible to move the file (filename) in (newFileName) because they are the same file.

Probably the last one it is not a problem. It occurs because the file is already lowercase....

What do you think?
 
Old 05-29-2005, 09:36 AM   #6
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 53
you are right. It's trickier than that.
Try this one:
Code:
for filename in `find .|tac`; do
   path_name=${filename%/*}
   short_fname=${filename##*/}
   lower_file=`echo $short_fname | tr [A-Z] [a-z]`
   if [ "$short_fname" != "$lower_file" ]; then
      mv $path_name/$short_fname $path_name/$lower_file
   fi
done
It seems to work
 
Old 05-29-2005, 05:20 PM   #7
cubax
Member
 
Registered: Nov 2004
Posts: 34

Original Poster
Rep: Reputation: 15
cool
Works.
You are my bash guru

Many thanks.

Ciao
 
  


Reply


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
UPPERCASE to lowercase command? pk21 Linux - General 4 06-12-2007 11:26 AM
kernel image name not all in lowercase? fatman Debian 3 02-16-2005 02:51 AM
[c++]to lowercase hylke Programming 3 05-16-2004 02:24 AM
renaming to lowercase locazor Linux - Software 1 01-02-2004 09:29 AM
rename to lowercase Jalalabee Linux - Newbie 11 09-10-2003 12:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:08 AM.

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