Change *.txt to *.csv

How can I rename all *.txt in a directory to *.csv files in the terminal (Mavericks). I tried following inside the directory:

mv *.txt *.csv

You need to loop over all files

for f in *.txt; do
    mv "$f" "${f%.txt}.csv"
done

If you have files with names starting with a . as well you might need to run

for f in *.txt .*.txt; do
    [[ -f "$f" ]] && mv "$f" "${f%.txt}.csv"
done

This also works well:

# change to the Zsh
zsh

# load the built-in zmv function
autoload -U zmv

# rename the files
zmv '(*).txt' '$1.csv'