I have a folder with about 1,700 files. They are all named like 1.txt
or 1497.txt
, etc. I would like to rename all the files so that all the filena
Let's assume you have files with datatype .dat in your folder. Just copy this code to a file named run.sh, make it executable by running chmode +x run.sh
and then execute using ./run.sh
:
#!/bin/bash
num=0
for i in *.dat
do
a=`printf "%05d" $num`
mv "$i" "filename_$a.dat"
let "num = $(($num + 1))"
done
This will convert all files in your folder to filename_00000.dat
, filename_00001.dat
, etc.