LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-03-2009, 12:02 AM   #16
vonbiber
Member
 
Registered: Apr 2009
Distribution: slackware 14.1 64-bit, slackware 14.2 64-bit, SystemRescueCD
Posts: 533

Rep: Reputation: 129Reputation: 129

I would go this way

[code]
#!/bin/sh

#set the current working directory
CWD=$PWD

find $CWD/* | while read f
do
if [ -d "$f" ]; then
#directory
continue
fi
#get extension
e=${f##*.}
if [ -z "$e" ]; then
#no extension
continue
elif [ "$e" != "Z" ]
#not a Z extension
continue
fi
#get the directory part
d=${f%/*}
#filename part
fn=${f##*/}
#name part (what's before .Z)
name=${fn%.Z}
newname="$(echo $name | tr '[:upper:]' '[:lower:]')"
if [ "$name" == "$newname" ]; then
#already lower case
continue
fi
#form the full path of the new name
g="$d/$newname.Z"
#rename the file
#please test before you do the actual renaming
echo "mv \"$f\" \"$g\""
#uncomment if everything looks ok
# mv "$f" "$g"
done
 
Old 10-03-2009, 01:54 AM   #17
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
a lot of your code are redundant.
Code:
find $CWD/* | while read f
do
if [ -d "$f" ]; then
#directory
continue
fi
#get extension
e=${f##*.}
if [ -z "$e" ]; then
#no extension
continue
elif [ "$e" != "Z" ]
#not a Z extension
continue
fi
you can just do
Code:
find $CWD -type f -name "*.Z"
. To get various info about the file , such as parent directory names, etc, you can use GNU find's printf option with specifiers.
 
Old 10-04-2009, 11:32 AM   #18
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Quote:
Originally Posted by DrLove73 View Post
That is very nice, but not all distributions use Bash v4, so I do not this this should be used for quite some time and/or with big warning it might not work on their systems.
Which is why I clearly said it was a version 4 option when I brought it up. But if you are using v4 (and most major distros should be upgrading to it before too long) then it's a much more efficient option than calling an external command, particularly if you need to do really big rename jobs on "thousands of files".


BTW, could you please fix your signature? That overly-long dashed line is breaking the page format. Thanks.
 
Old 10-04-2009, 01:08 PM   #19
DrLove73
Senior Member
 
Registered: Sep 2009
Location: Srbobran, Serbia
Distribution: CentOS 5.5 i386 & x86_64
Posts: 1,118
Blog Entries: 1

Rep: Reputation: 129Reputation: 129
Quote:
Originally Posted by David the H. View Post
Which is why I clearly said it was a version 4 option when I brought it up. But if you are using v4 (and most major distros should be upgrading to it before too long) then it's a much more efficient option than calling an external command, particularly if you need to do really big rename jobs on "thousands of files".
CentOS/RHEL have featuries lockdown for ~5 years, untill the next major version. If you count those still on version 4.x, there is very large base of server oriented users that will for quite some time be on Bash v3. But there is a god deal of them not knowing their Bash version.
Maybe just to rephrase and say something like "If you have newer version of Bash, v4...." so those who are not aware of their version would stop and think a little... You would be surprised how little people use their grey cells. There is a very good reason for "idiot proof" technology.

Quote:
Originally Posted by David the H. View Post
BTW, could you please fix your signature? That overly-long dashed line is breaking the page format. Thanks.
Hm, I thought I already did. Oh well, I shortened it now.
 
  


Reply



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
Lowercase to Uppercase stellafrank Linux - Software 2 11-16-2006 05:46 AM
rename script won't change uppercase to lowercase on fat32 pwc101 Programming 4 09-27-2006 05:16 PM
[c++]to lowercase hylke Programming 3 05-16-2004 01:24 AM
renaming to lowercase locazor Linux - Software 1 01-02-2004 08:29 AM
rename to lowercase Jalalabee Linux - Newbie 11 09-10-2003 11:44 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:42 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