11.08.2007

rename file extensions easily in Unix

In dos you could:
move *.txt *.cvs

but the wildcard characters don't work that way in unix. You must do something like the following, where EXT1 is the original extension and EXT2 is the new one:

for i in *.EXT1
do
mv $i ${i%.EXT1}.EXT2
done

for example: to rename all .txt files to .ascii run the following shell script:
for i in *.txt
do
mv $i ${i%.txt}.ascii
done

No comments: