Say, I have several files in a directory.
How do I rename all of them to "001", "002", etc., saving their current file extensions?
Say, I have several files in a directory.
How do I rename all of them to "001", "002", etc., saving their current file extensions?
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".