Shell Command – Remove File Extensions in Unix

bashshellterminalunix

I have a directory with automatically generated files that all end with the .sample extension.
I would like to have a way to remove the .sample extension from them all in one terminal command.

I tried this:

mv ./{$1}*.sample ./$1

But it doesn't work because I'm definitely placing the {$1} in the wrong place or way. Can anyone point to the right direction?

Thanks in advance.

Best Answer

One of the many way to do that:

for i in *.sample; do NEWNAME=`echo "$i" | sed 's/\.sample//'`; mv "$i" "$NEWNAME"; done