Search code examples
linuxbashfilenames

Change filenames in a specific folder through bash


I have a folder FOLDER1 with different files in it.

I have several files in the folder with an extension .png

I would like to change the filename of all the files with extension .png with a bash script. I tried to write one but I still didn't arrive to have what I want.

#!/bin/bash
# make sure you always put $f in double quotes to avoid any nasty surprises i.e. "$f"
i=0
for f in *.png
do
  echo "${i}Processing $f file..."
  i+=1;
  echo ${i}
  # rm "$f"
done

At the end of the script I would like to have all the files named like:

c-1.png

c-2.png

c-3.png

...

...

...

Could you help me? Thanks


Solution

  • Sorry, I found my solution .

    This code is working perfectly.

    #!/bin/bash
    # make sure you always put $f in double quotes to avoid any nasty surprises i.e. "$f"
    i=0
    for f in *.png
    do
      echo "$i Processing $f file..."
      i=$((i+1))
      mv $f "c-"$i.png
      #echo ${i}
    done