Tuesday, December 20, 2005

Tips & Tricks : การ Rename ไฟล์ด้วย command-line ทีละหลายๆไฟล์

Rename files on the command line

This fella on a mailing list I’m on wants to rename files (specifically, .mpe to .mpg) on his Mac OS X box using the command line, but doesn’t know how. The great Robert Citek to the rescue! Here’s his suggestion:

for file in *.mpe ; do mv $file ${file%.mpe}.mpg ; done

However, Robert then went on to make this interesting suggestion: "Personally, I like to echo the command and proof it. If I like it I can then pipe it into bash. That allows you to catch the case when there are several .mpg files and no .mpe files."

for file in *.mpe ; do echo mv $file ${file%.mpe}.mpg; done | bash

Great idea, Robert! Thanks!

Oh, and by the way: this same technique works just fine and dandy on a Linux box as well.
ขอขอบคุณ http://opensource.weblogsinc.com/entry/1234000790067375/

No comments:

Post a Comment