Oct 7, 2002 #1 SaltyDuke Programmer Joined Sep 18, 2002 Messages 140 Location 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
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
Oct 7, 2002 #2 flugh Technical User Joined Aug 23, 2002 Messages 655 Location US 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 Upvote 0 Downvote
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
Oct 7, 2002 #3 nwardez Technical User Joined Oct 2, 2002 Messages 174 Location FR 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 ... Upvote 0 Downvote
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 ...
Oct 10, 2002 #4 fluid11 IS-IT--Management Joined Jan 22, 2002 Messages 1,627 Location US ...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 Upvote 0 Downvote
...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