Tuesday, July 07, 2009

Rename extension of all files in a folder

Here is a way to do this from command line

ls *.sh | sed 's/\(.*\)\.sh/ & \1.pl/' | xargs -L1 mv

Ok there are four commands here all piped.


I used ls to filter all .sh files.

I used sed to substitute all .sh to .pl. What it does is creates argument for mv command. Test it with ls *.pl | sed 's/\(.*\)\.pl/ & \1.sh/'

I used xargs with mv to move sh to pl. the –L switch is used to get input form sed pipe

No comments: