Change *.txt to *.csv

bashterminal

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

Best Answer

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