Showing posts with label command. Show all posts
Showing posts with label command. Show all posts

Thursday, February 26, 2015

Renaming multiple files in single command in Linux


In Linux renaming a file or two is very simple with 'mv' but how about hundred or thousand in one shot?

Here I have list of files:

doc1.TXT.read
doc2.TXT.read
doc3.TXT.read
doc4.TXT.read
doc5.TXT.read
doc6.TXT.read
doc7.TXT.read
doc8.TXT.read

Now, I want to rename it to doc1.txt, doc2.txt so on and so forth i.e changing the capital .TXT to lower case .txt and remove the .read extension

for f in *.TXT.read ; do mv -i "$f" "${f%%.*}.txt" ; done

The result will be:

doc1.txt
doc2.txt
doc3.txt
doc4.txt
doc5.txt
doc6.txt
doc7.txt
doc8.txt

And there you have it !!