FreeBSD - Tutorials, Security
Home   Archives   Sitemap   About   Contact

How to rename files/directories to uppercase/lowercase character names

Home NEW! Unix Forum News 100 Tips and Tricks Website Development Server Operating Systems Databases
 Ivorde.ROarrow Server Operating Systems arrowAdministration GuidesarrowHow to rename files/directories to uppercase/lowercase character names 

Article Sections

    Hello, Guest !
User name:
Password:
 
Google

 SSD VPS Hosting - Vpsie.com
 Mo.nitor.me
 Ivorde forum
 FreeBSD Tutorials
 Linux LVM Commands
 Free Shell Accounts
 FreeBSD Project
 FreeBSD Handbook
 Advanced Bash-Scripting Guide
 The OpenBSD Project
 Distrowatch
 FreeBSD Handbook


Apache Webserver Home Page

Blog, intrebari si raspunsuri despre Leasing

Posted on: 17 Jun 2008
Author: mandrei
Section: Server Operating Systems | Administration Guides
Views: 4654
Comments: 4 (Add)

How to rename files/directories to uppercase/lowercase character names
How to rename files/directories to upper case/lower case character names, convert the files names to lower case, convert the directories and all files in the subdirectories to upper case, convert the files names to upper case, convert the directories and all files in the subdirectories to upper case

 



I have created in my current working directory four files (A, B, C, D) and four directories (AA, BB, CC, DD) as follows:

$ ls -l
total 16
-rw------- 1 root wheel 0 Jun 17 10:29 A
drwx------ 2 root wheel 512 Jun 17 10:29 AA
-rw------- 1 root wheel 0 Jun 17 10:29 B
drwx------ 2 root wheel 512 Jun 17 10:29 BB
-rw------- 1 root wheel 0 Jun 17 10:29 C
drwx------ 2 root wheel 512 Jun 17 10:29 CC
-rw------- 1 root wheel 0 Jun 17 10:29 D
drwx------ 2 root wheel 512 Jun 17 10:29 DD

Now let's play a little with these upper-case names files and directories.

1) Rename all directories to lower case names

$ for i in `find . -type d`; do new_name=`echo $i | tr '[A-Z]' '[a-z]'`; mv $i $new_name ; done
$ ls -l
total 16
-rw------- 1 root wheel 0 Jun 17 10:29 A
-rw------- 1 root wheel 0 Jun 17 10:29 B
-rw------- 1 root wheel 0 Jun 17 10:29 C
-rw------- 1 root wheel 0 Jun 17 10:29 D
drwx------ 2 root wheel 512 Jun 17 10:29 aa
drwx------ 2 root wheel 512 Jun 17 10:29 bb
drwx------ 2 root wheel 512 Jun 17 10:29 cc
drwx------ 2 root wheel 512 Jun 17 10:29 dd

Above we see directories renamed in lower cased names.

2) Rename all files to lower case names

$ for i in `find . -type f`; do new_name=`echo $i | tr '[A-Z]' '[a-z]'`; mv $i $new_name ; done
$ ls -l
total 16
-rw------- 1 root wheel 0 Jun 17 10:29 a
drwx------ 2 root wheel 512 Jun 17 10:29 aa
-rw------- 1 root wheel 0 Jun 17 10:29 b
drwx------ 2 root wheel 512 Jun 17 10:29 bb
-rw------- 1 root wheel 0 Jun 17 10:29 c
drwx------ 2 root wheel 512 Jun 17 10:29 cc
-rw------- 1 root wheel 0 Jun 17 10:29 d
drwx------ 2 root wheel 512 Jun 17 10:29 dd

All files have been renamed to lower cased names.

3) Rename all files and directories to upper case names

$ for i in `find .`; do new_name=`echo $i | tr '[a-z]' '[A-Z]'`; mv $i $new_name ; done
ls -l
total 16
-rw------- 1 root wheel 0 Jun 17 10:29 A
drwx------ 2 root wheel 512 Jun 17 10:29 AA
-rw------- 1 root wheel 0 Jun 17 10:29 B
drwx------ 2 root wheel 512 Jun 17 10:29 BB
-rw------- 1 root wheel 0 Jun 17 10:29 C
drwx------ 2 root wheel 512 Jun 17 10:29 CC
-rw------- 1 root wheel 0 Jun 17 10:29 D
drwx------ 2 root wheel 512 Jun 17 10:29 DD

All files and directories have been renamed to upper cased names.

Below there's a little script that converts all upper cased files&(sub)directories to lower cased names in a path:

#!/bin/sh
DIR=/where/to/find/and/replace
for i in `find $DIR`
do
new_name=`echo $i | tr '[A-Z]' '[a-z]'`
mv $i $new_name
done

To make this little script more interesting you should play a little with the find parameters (-name, -inum -mtime -ctime, etc.). For example, if you need to rename only .EXE types of files to lower cased names, you should use find . -name *.EXE.

Also read
How to switch lower case to upper case and upper case to lower case in a string
How to convert lower case to upper case letters in a shell script/command

Bookmarks: Echo "How to rename files/directories to uppercase/lowercase character names" around:
del.icio.usdiggFurlYahooMyWebGoogleBookmarksFaceBookTechnocratti
-------------------advertising-----------------

Other articles in Server Operating Systems / Administration Guides
» Unix,Linux,FreeBSD - How to rename a list of files, replacing spaces inside their names
» Take advantage of Unix Environment Variables when performing backups or restore points
» How to remove first/last character from a string using SED
» How to cut out first last n characters from each file name, from a filelist
» Print queues in AIX 5L - How to list print queues in AIX




Contact webmaster regarding this article
Register or Login to post your article
Hello, Guest ! You can Login or Register to www.ivorde.ro!

 Post comment:

Name:
Title:
Comment:
Please type the word you see in the image (anti-spam verification). Refresh the page if you don't understand the word.
Verification code
Allowed HTML Tags for comments:<p><strong><em><u><h1><h2><h3><h4><h5><h6><img><li>
<ol><ul><span><div><br><ins><del>

4 comment(s) to How to rename files/directories to uppercase/lowercase character names:

1. Re: How to rename files/directories to uppercase/lowercase character names
Instructor by Rich at August 03rd, 2011 - 20:42
I have looked at several web sites trying to find a simple way of renaming folder/files from uppercase to lower. GREAT job on the examples above!!!!

2. Re: How to rename files/directories to uppercase/lowercase character names
one more thing to replacing names by Andrei at September 26th, 2008 - 14:53
Be careful to test it with files that contain metacharacters or spaces in their names. Probably will not work with those files.

3. Re: How to rename files/directories to uppercase/lowercase character names
Possible, but dangerous by Andrei at September 26th, 2008 - 14:51
cd to the directory you want and use find piped to xargs:
Something like the following command should rename replacing a-z with A-Z only in files (not directories) in your curent directory and subdirectories:

for i in `find . -type f`; do dir=`dirname $i`; file=`basename $i`; newfile=`echo $file | tr '[a-z]' '[A-Z]'`; mv "${dir}/${file}" "${dir}/${newfile}" ; done

Doing something like this with subdirectories from a simple script I find it a little hard (because the for loop uses subdirectories names in initial find results and changes it on the way, resulting in Xth loop not finding initial directories because their base directories were renamed in X-t loop). Hope you understand this. Contact me from my contact form if you have further questions. P.S.:
MAKE SURE TO TEST IT first !! I offer no waranty to this command.

4. Re: How to rename files/directories to uppercase/lowercase character names
Unix Learner by Pollyanna at August 17th, 2008 - 18:34
Is it possible to modify the script to recursively rename all sub-directories and it's files to upper case names?

   Latest topics on the forum:
 
   Most viewed articles:
Qmail relay to smarthost: How to route all mail to a smarthost - 6580 views
How to remove first/last character from a string using SED - 6425 views
FreeBSD: Add/remove an additional IP alias - 6228 views
ProFTPd + MySQL - 530 Login incorrect - 5374 views
EXIM 4 relay to smarthost: How to route all mail except local domain - 5336 views

   Latest 10 articles:
Qmail relay to smarthost: How to route all mail to a smarthost - 03 Feb 2009
EXIM 4 relay to smarthost: How to route all mail except local domain - 03 Feb 2009
Windows XP: print LISTEN ports and network connections using netstat - 30 Jan 2009
How to cut out first last n characters from each file name, from a filelist - 04 Nov 2008
Mozilla Firefox3 is now released - 18 Jun 2008
How to switch lower case to upper case and upper case to lower case in a string - 17 Jun 2008
How to rename files/directories to uppercase/lowercase character names - 17 Jun 2008
How to convert lower case to upper case letters in a shell script/command - 17 Jun 2008
Unix,Linux,FreeBSD - How to rename a list of files, replacing spaces inside their names - 12 Jun 2008
How to change a user's password in AIX with the output from ECHO command - 21 May 2008


Archives
» 2007  |  June  |  October  |  November  |  December
» 2008  |  January  |  February  |  March  |  April  |  May  |  June  |  November
» 2009  |  January  |  February



Home | Archives | Sitemap | About | Contact

Designed and developed by Andrei Manescu. Optimized for Mozilla Firefox.  
Copyright 2007 Andrei Manescu
All trademarks and copyrights on this page are owned by their respective owners. Comments are owned by those who posted them.
Valid W3 Document Valid XHTML 1.0 Transitional Valid CSS! The FreeBSD Project Viewable With Any Browser