Linux Help
guides forums blogs
Home Desktops Distributions ISO Images Logos Newbies Reviews Software Support & Resources Linuxhelp Wiki

Welcome Guest ( Log In | Register )



Advanced DNS Management
New ZoneEdit. New Managment.

FREE DNS Is Back

Sign Up Now
 
Reply to this topicStart new topic
> Moving Groups Of Files From Upper To Low
Corey
post Jul 15 2003, 09:01 AM
Post #1


Its GNU/Linuxhelp.net
*******

Group: Admin
Posts: 1,254
Joined: 21-September 02
From: St John's, Newfoundland, Canada
Member No.: 3



Often times when you transfer files from Windows to Linux, they end up with all Capital letters. While generally, this isn't much of a problem, sometimes this includes large directories and Linux will not see "FILENAME.EXE" the same as "filename.exe". The solution is to issue the following perl command to rename everything in a directory from upper to lower case:

QUOTE
perl -le 'rename $_, lc( $_ ) foreach <*>'


This "tip" is available through the random tip son the linuxhelp.ca frontpage.


--------------------
Corey Quilliam
(former) Linuxhelp.ca Administrator
cquilliam-AT-gmail-dot-com

Want to help out Linuxhelp.net? Check out our Linuxhelp Wiki and see if there are some articles you would like to submit!!

--
Ubuntu 8.04 64-bit - Work Laptop (HP-Compaq NC6400 Core2)
Kubuntu 8.04 64-bit - Desktop (HP m8120n QuadCore)
Ubuntu 6.04 - Server (I'm not upgrading this baby until support runs out in 2012) (Some old POS dell)
Go to the top of the page
 
+Quote Post
Hemant
post Dec 10 2003, 05:42 AM
Post #2


RMS is my Hero
******

Group: Support Specialist
Posts: 782
Joined: 6-October 02
From: Trichy,INDIA
Member No.: 29



just a suggestion...
We should also explain the tricks


--------------------
Hemant Kumar
user posted image
hemant@linuxhelp.net
Go to the top of the page
 
+Quote Post
hughesjr
post Dec 10 2003, 06:41 AM
Post #3


Its GNU/Linuxhelp.net
*******

Group: Admin
Posts: 3,433
Joined: 25-July 03
From: Corpus Chrsiti, TX, USA
Member No.: 1,151



Ok ... here is the explaination:

PERL is magic laugh.gif
----------------------
Actually, the perl -l is to run perl, -e switch allows you to execute the information inside the quotes with the perl interpretor ... it's like running a perl script that contains the information inside the quotes ... in this case the perl command that is executed is: rename $_, lc( $_ ) foreach <*>

$_ (in perl) is the topic ... which in generic terms means the currently selected item...if you want a more detailed explaination of topic, see this. In this code, the topic is going to be a filename.

lc() is a function in perl to convert text to lowercase ... in this example, it converts $_ (the filename) to lowercase.

rename x,y in perl will rename file x to the name y ... it is very similar to the command mv in bash (except there is a comma between filenames). In this case $_ (the original filename) is renamed to lc($_) the lowercase filename.

foreach defines a list of items to do sometime on ... in this case <*> will generate a list including all files in a directory...try this command to see a list of all the files in a directory: perl -le 'print $_ foreach <*>'

So, put it all together and perl -le 'rename $_, lc( $_ ) foreach <*>' will convert all filenames in a directory to thier lowercase equivalant.

I actually know a little bit about perl ... see my old website ... which I haven't updated since 1999 (i think) ... I don't even know the passwords to make changes to the site anymore....(WOW what a flashback!)


--------------------
Johnny Hughes
hughesjr@linuxhelp.net
Enterprise Alternatives: CentOS, WhiteBoxEL
Favorite Workstation Distros (in order): CentOS, Gentoo, Debian Sarge, Ubuntu, Mandrake, FedoraCore, Slackware, SUSE
Favorite Server Distros (in order): CentOS, WhiteBoxEL, Debian Sarge, Slackware, Mandrake, FedoraCore, Gentoo, SUSE
Go to the top of the page
 
+Quote Post
Hemant
post Dec 11 2003, 05:26 AM
Post #4


RMS is my Hero
******

Group: Support Specialist
Posts: 782
Joined: 6-October 02
From: Trichy,INDIA
Member No.: 29



Yeah..Thanks for explanation...i have checked your site also...
interesting....


--------------------
Hemant Kumar
user posted image
hemant@linuxhelp.net
Go to the top of the page
 
+Quote Post
hughesjr
post Dec 11 2003, 07:43 AM
Post #5


Its GNU/Linuxhelp.net
*******

Group: Admin
Posts: 3,433
Joined: 25-July 03
From: Corpus Chrsiti, TX, USA
Member No.: 1,151



Just so everyone knows ... I was an NT and UNIX guy back in 1999 (I was just playing around with Linux on a webserver or 2 back then)...I am a Linux guy now! laugh.gif

(Like I said before...I haven't changed that site since 1999).
-----------------------------------------------
And now, back on topic:

For anyone who would rather convert upper to lower case with a shell script...here it is (I named it lowerit.sh):

CODE
#!/bin/sh
# lowerit
# convert all file names in the current directory to lower case
# only operates on plain files--does not change the name of directories
# will ask for verification before overwriting an existing file
for x in `ls`
do
  if [ ! -f $x ]; then
    continue
  fi
  lc=`echo $x  | tr '[A-Z]' '[a-z]'`
  if [ $lc != $x ]; then
        mv -i $x $lc
  fi
done
# End of lowerit script


The above file needs to be in the directory you want to change files in ... and it won't currently do files that start with a . (like .Abc123Z) won't get converted ... because most . files are setup files and you don't want to change their case. If you do want to also change the case of . files, change the line for x in `ls` to for x in `ls -a`


--------------------
Johnny Hughes
hughesjr@linuxhelp.net
Enterprise Alternatives: CentOS, WhiteBoxEL
Favorite Workstation Distros (in order): CentOS, Gentoo, Debian Sarge, Ubuntu, Mandrake, FedoraCore, Slackware, SUSE
Favorite Server Distros (in order): CentOS, WhiteBoxEL, Debian Sarge, Slackware, Mandrake, FedoraCore, Gentoo, SUSE
Go to the top of the page
 
+Quote Post
Hemant
post Dec 20 2003, 05:02 AM
Post #6


RMS is my Hero
******

Group: Support Specialist
Posts: 782
Joined: 6-October 02
From: Trichy,INDIA
Member No.: 29



How about renaming whole filename from uppercase to lowercase..here is a solution using gawk..
$ ls -l|awk `{printf("mv %s %sn",$9,totupper($9))|"/bin/bash"}`


--------------------
Hemant Kumar
user posted image
hemant@linuxhelp.net
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 22nd November 2017 - 02:34 AM