Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

renaming files

Status
Not open for further replies.

SaltyDuke

Programmer
Sep 18, 2002
140
IE
hello.

i have a file called: hello.txt

and i would like to change it to HELLO.txt for reasons of National Security (well not relly ;-) )

so how do i go about doing this?? in other words, is there a "rename" command for filenames in Linux??

thanx
 
Ok, there's prettier ways to do this, but it'll work. Using bash (my shell of choice):
Code:
for i in *.txt; do mv "$i" `echo "$i" | tr [a-z] [A-Z]`; done
But that moves every hello.txt to HELLO.TXT. If the cap'd .TXT is a problem, next do:
Code:
for i in *.TXT; do mv "$i" `echo "$i" | tr [TXT] [txt]`; done
The extra " quotation marks will compensate for any spaces in your filenames.

I'm sure there's a more efficient way to do it, maybe using 'cut' and another variable, but this will get it done either way :)
 
Hi,

In 1 phase

for i in *.txt; do mv $i `echo $i | awk -F\. '{print toupper($1)}'`.txt; done

But if the job only concerns 1 file, "mv hello.txt HELLO.txt" is probable the shortest way ...
 
...uhhhh, how about "mv hello.txt HELLO.txt". Its a little simpler than writing a script to rename a file.

The mv command is used to both rename and move files/directories in Unix/Linux.


ChrisP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top