1

I have tons of image inside a folder and it also has different file types. I have tried googling for an answer but I can't seem to find one. I wanted the files to be named 1.jpg, 2.png, 3.gif. . . n.JPEG. Could someone help me out with this?

3
  • 1
    You can use rename or a loop Commented Oct 6, 2015 at 15:03
  • have a look at man rename (which is a perl tool, maybe you have to install perl). Commented Oct 6, 2015 at 15:04
  • what does the perlexp mean? Commented Oct 6, 2015 at 15:08

1 Answer 1

1

Try the command below:

cd path_to_your_files
declare -i i=0; for f in *; do i=$((i+1));fn=$i".${f##*.}"; mv "$f" "$fn"; done

Make note that the command above is a bash script.

Sign up to request clarification or add additional context in comments.

7 Comments

Should the path be a string? It gives me an error mv: cannot stat ‘/home/vianney/Downloads/Image Processing/Images/*’: No such file or directory
I edited my command. And are you sure that your OS is using BASH as in the default?
Check default shell by: echo $SHELL
result of echo $SHELL == /bin/bash
show me the output of command: for f in path_to_your_files/*; do echo "$f", done;
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.