- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Script to find any capital letter and change i...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2007 11:46 PM
06-05-2007 11:46 PM
Thanks!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2007 12:50 AM
06-06-2007 12:50 AM
Re: Script to find any capital letter and change it to lower case?
this worked for that directory
for file in `ls`
do
mv $file `echo $file | tr '[:upper:]' '[:lower:]'`
done
i would add * after ls if you want it to do subdirectories also
- Tags:
- tr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2007 12:52 AM
06-06-2007 12:52 AM
Re: Script to find any capital letter and change it to lower case?
lname=$(echo $fname | tr "[:upper:]" "[:lower:]")
[ $lname != $fname ] && mv $fname $lname
done
Beware that this script may run a very long time (depending on amount of directories) since it finds every file and tests for capital letters.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2007 12:53 AM
06-06-2007 12:53 AM
Re: Script to find any capital letter and change it to lower case?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2007 12:56 AM
06-06-2007 12:56 AM
Re: Script to find any capital letter and change it to lower case?
#!/usr/bin/sh
FPATH=/foo/bar
find ${FPATH} -type f -print > /tmp/flist.${$}.out
while read L
do
{
DIR=${L%/*}
F1=${L##*/}
F2=$(echo ${F1} | tr '[:upper:]' '[:lower:]')
if [ ${F1} != ${F2} ]
then
mv ${DIR}/${F1} ${DIR}/${F2}
fi
} done < /tmp/flist.${$}.out
rm -f /tmp/flist.${$}.out
exit 0
PCS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2007 01:00 AM
06-06-2007 01:00 AM
SolutionPerl makes this easy. This will lowercase the names of all files with any uppercase letters. This will be done recursively in the directory (or directories) that you pass as an argument. Only files (not directory names) will be changed.
The _current_working_ directory will be used if you run the script without any argument!
# cat /.rename
#!/usr/bin/perl
#@(#)rename $ Find files with uppercase letters and lowercase - JRF $
use strict;
use warnings;
use File::Find;
my @path = @ARGV ? @ARGV : getcwd() =~ m{^/$} ? ('/') : ('.');
my @files = ();
my ( $oldname, $newname );
find( sub { push( @files, $File::Find::name ) if m/[A-Z]+/ && -f $_ }, @path );
for $oldname (@files) {
($newname = $oldname) =~ tr [A-Z] [a-z];
rename( $oldname, $newname );
}
1;
...run as:
# ./rename /path
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2007 03:47 AM
06-06-2007 03:47 AM
Re: Script to find any capital letter and change it to lower case?
# find . -type f | awk '{f=tolower($0);system("mv "$0" "f)}'
~hope it helps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2007 03:54 AM
06-06-2007 03:54 AM
Re: Script to find any capital letter and change it to lower case?
suppose that you have files "myfile" (the good) and "MyfilE" (the bad). Unless a test is done first the "mv MyfilE myfile" will overwrite the existing file.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2007 03:55 AM
06-06-2007 03:55 AM
Re: Script to find any capital letter and change it to lower case?
Passing the entire $0 to tolower() causes directory names containing uppercase characters to also be converted to lowercase, resulting in "mv: ... No such file or directory".
PCS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2007 04:50 AM
06-06-2007 04:50 AM
Re: Script to find any capital letter and change it to lower case?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2007 05:00 AM
06-06-2007 05:00 AM
Re: Script to find any capital letter and change it to lower case?
Clay makes an excellent point! We can easily handle this and cleanup the problem PCS noted:
# cat ./rename
#!/usr/bin/perl
#@(#)rename $ Find files with uppercase letters and lowercase - JRF $
use strict;
use warnings;
use Cwd;
use File::Basename;
use File::Find;
my @path = @ARGV ? @ARGV : getcwd() =~ m{^/$} ? ('/') : ('.');
my @files = ();
my ( $dirname, $basename, $oldname, $newname );
find( sub { push( @files, $File::Find::name ) if -f $_ && m/[A-Z]+/ },
@path );
for $oldname (@files) {
$dirname = dirname($oldname);
$basename = basename($oldname);
( $newname = $basename ) =~ tr [A-Z] [a-z];
$newname = $dirname . '/' . $newname;
if ( -f $newname ) {
print STDERR "'$oldname' not renamed; '$newname' exists!\n";
}
else {
rename( $oldname, $newname )
or print STDERR "'$oldname' not changed\n";
}
}
1;
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2007 07:24 AM
06-06-2007 07:24 AM
Re: Script to find any capital letter and change it to lower case?
#!/bin/ksh
for file in `ls`
do
mv $file `echo $file |tr "[:lower:]" "[:upper:]"`
done