1

Say, I have several files in a directory.

How do I rename all of them to "001", "002", etc., saving their current file extensions?

1 Answers1

5
  • Terminal method
    cd (change directory) to the folder.
    run command:
  • Command 1

    rename -n -v 'our $n; my $zn=sprintf("%03d", ++$n); s/.*\./$zn./' *.*
    

This will display the changes. Remove -n for actual rename.
Answer from @Kusalananda

  • Command 2

    a=1; for i in *.*; do new=$(printf "%03d" "$a"); mv -i -- "$i" "$new.${i##*.}"; let a=a+1; done
    
  • GUI method
    Select all files to be renamed.
    Right click and select rename.
    Delete [Original file name] from the option area. Click on "Add" and select 001, 002, 003, 004.
    Click on "Rename".

rename-1

rename-2

enter image description here

Vijay
  • 8,056