Skip to main content
Notice removed Needs detailed answers by nohillside
ls *.txt |awk '{print "mv "$1" " substr($1,1,(index($1,".txt")))"csv"}' |sh

Command explanation:

ls *.txt lists files ending with txt

| awk '{print "mv "$1" " substr($1,1,(index($1,".txt")))"csv"} prints the command that allows to rename the previous files listed with txt to csv

| sh executes the previously printed command, thus effectively renaming the files

Note: if you want to list all files including hidden files (those starting with .) use ls -a *.txt instead

ls *.txt |awk '{print "mv "$1" " substr($1,1,(index($1,".txt")))"csv"}' |sh
ls *.txt |awk '{print "mv "$1" " substr($1,1,(index($1,".txt")))"csv"}' |sh

Command explanation:

ls *.txt lists files ending with txt

| awk '{print "mv "$1" " substr($1,1,(index($1,".txt")))"csv"} prints the command that allows to rename the previous files listed with txt to csv

| sh executes the previously printed command, thus effectively renaming the files

Note: if you want to list all files including hidden files (those starting with .) use ls -a *.txt instead

added 4 characters in body
Source Link
klanomath
  • 67k
  • 10
  • 135
  • 204

ls *.txt |awk '{print "mv "$1" " substr($1,1,(index($1,".txt")))"csv"}' |sh

ls *.txt |awk '{print "mv "$1" " substr($1,1,(index($1,".txt")))"csv"}' |sh

ls *.txt |awk '{print "mv "$1" " substr($1,1,(index($1,".txt")))"csv"}' |sh

ls *.txt |awk '{print "mv "$1" " substr($1,1,(index($1,".txt")))"csv"}' |sh
Notice added Needs detailed answers by bmike
Source Link

ls *.txt |awk '{print "mv "$1" " substr($1,1,(index($1,".txt")))"csv"}' |sh