# Converting file names to upper case

**URL:** <https://community.unix.com/t/converting-file-names-to-upper-case/158672>\
**Category:** Shell Programming and Scripting\
**Created:** [January 10, 2006, 4:09am UTC](https://community.unix.com/t/converting-file-names-to-upper-case/158672 "2006-01-10T04:09:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sabari\_Nath\_S](https://community.unix.com/letter_avatar/sabari_nath_s/32/6_449c533f586939b6e5f246632a46421f.png) [@Sabari\_Nath\_S](https://community.unix.com/u/Sabari_Nath_S)\
**Post date:** [January 10, 2006, 4:09am UTC](https://community.unix.com/t/converting-file-names-to-upper-case/158672/1 "2006-01-10T04:09:04Z")

</div>

Hi all,

I am trying to rename all my files in a directory to their upper case counterparts .... I want to do this in a single command and not through shell script ... I started off thinking it wud be simple but got stuck up in middle since tr does not work the way i thought ...

This is what i tried ...

ls | xargs -l1 -t -i mv {} `echo {} | tr '[a-z]' '[A-Z]'`

Here tr does not seem to do any work and just returns the file name as such .. So in effect i am renaming a file to that name itself ...

mv try.cc try.cc  
mv: try.cc and try.cc are identical  
mv typescript typescript  
mv: typescript and typescript are identical

Why is this happening ?? And can anyone suggest me a solution

---

<div class="post-metadata">

**Author:** ![linuxpenguin](https://community.unix.com/user_avatar/community.unix.com/linuxpenguin/32/60_2.png) [@linuxpenguin](https://community.unix.com/u/linuxpenguin)\
**Post date:** [January 10, 2006, 6:33pm UTC](https://community.unix.com/t/converting-file-names-to-upper-case/158672/2 "2006-01-10T18:33:58Z")

</div>

for i in \*  
do  
mv $i `echo $i|awk '{print toupper($0)}'`  
done

now i dunno if you can consider this as a one line command, but i think it has to be, coz you cant execute each of the above line separately by itself to get your result

---

<div class="post-metadata">

**Author:** ![zazzybob](https://community.unix.com/user_avatar/community.unix.com/zazzybob/32/112_2.png) [@zazzybob](https://community.unix.com/u/zazzybob)\
**Post date:** [January 10, 2006, 6:42pm UTC](https://community.unix.com/t/converting-file-names-to-upper-case/158672/3 "2006-01-10T18:42:15Z")

</div>

Not one line, but efficient with ksh builtins...

```nohighlight
# ls
file_1 file_2 file_3
# ls | while read filename; do
> typeset -u uppercase
> uppercase=${filename}
> mv ${filename} ${uppercase}
> done
# ls
FILE_1 FILE_2 FILE_3

```

Cheers  
ZB

---

<div class="post-metadata">

**Author:** ![Sabari\_Nath\_S](https://community.unix.com/letter_avatar/sabari_nath_s/32/6_449c533f586939b6e5f246632a46421f.png) [@Sabari\_Nath\_S](https://community.unix.com/u/Sabari_Nath_S)\
**Post date:** [January 12, 2006, 2:19am UTC](https://community.unix.com/t/converting-file-names-to-upper-case/158672/4 "2006-01-12T02:19:10Z")

</div>

Here my list of files to be renamed comes from some other command like find or something ... so i wud need to use xargs for doing this Also i want to do rename interactively ....

even when i put this awk part in xargs as below :

ls | xargs -l1 -t -i echo {} `echo {}|awk '{print toupper($0)}'`

awk doesnt work as tr in my first post...

where as here wc works

ls | xargs -l1 -t -i echo {} `echo {}|wc`

Can anyone tell me the reason why this happens ???

---

<div class="post-metadata">

**Author:** ![Perderabo](https://community.unix.com/user_avatar/community.unix.com/perderabo/32/27_2.png) [@Perderabo](https://community.unix.com/u/Perderabo)\
**Post date:** [January 12, 2006, 6:27am UTC](https://community.unix.com/t/converting-file-names-to-upper-case/158672/5 "2006-01-12T06:27:29Z")

</div>

> [@sabari nath s](#):
>
> ls | xargs -l1 -t -i echo {} `echo {}|awk '{print toupper($0)}'`  
> `echo {}|wc`
> 
> Can anyone tell me the reason why this happens ???

Neither command works for me. You must be testing in a directory with only a few two character filenames if you think the second one works. Create a few longer filenames. The shell sees `echo {} | wc`; so it runs that pipeline and it gets "{} 1 1 3" which it replaces in your command. So then you run:  
ls | xargs -l1 -t -i echo {} {} 1 1 3

---

<div class="post-metadata">

**Author:** ![linuxpenguin](https://community.unix.com/user_avatar/community.unix.com/linuxpenguin/32/60_2.png) [@linuxpenguin](https://community.unix.com/u/linuxpenguin)\
**Post date:** [January 12, 2006, 12:38pm UTC](https://community.unix.com/t/converting-file-names-to-upper-case/158672/6 "2006-01-12T12:38:21Z")

</div>

hmm, well if it is output of command find, you can pipe it to a for or while loop as follows, instead of using the xargs.

=\>find . | while read a  
do  
mv "$a" `echo "$a"|awk '{print toupper($a)}'`  
done  
mv: `.' and `./.' are the same file

if this still doesnt fit in your scenario, tell us what is that makes you so mandatory that you just cant do without using xargs?
