Saturday, October 4, 2008

rename files with same first name but different extentions

The scenario is this. You have a folder/directory with the following files:
a.txt, a.ps, a.pdf
and you want to change the file names to
b.txt, b.ps, b.pdf
Here is how to do it.

for file in `ls a.*`
do
mv $file b.${file##*.}
done

basically the ${file##*.} extracts the extensions of the file. On the same note ${file%*.} will extract the first names of the files.

got it from this page :)

No comments: