Saturday, April 27, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 467  / 2 Years ago, thu, june 23, 2022, 7:54:06

My Problem, that I've got a folder with many different files like:



xxxxxxxxx.avi       yyyyyyy.jpg         zzz.txt


And I want to rename them into



001.avi  002.jpg  003.txt


It's not working with thunar rename, because the filenames are not all the same length.



Maybe with rename 's/.*......, but I am kinda stuck...



Thanks for any suggestions


More From » rename

 Answers
1

If you are comfortable with a command line solution, you could do something like this, in bash



i=1
for file in *.*; do
printf -v newfile "%03d.%s" $((i++)) ${file##*.}
echo mv -v -- "$file" "$newfile"
done


The echo will prevent it from actually making any changes (it will just output a list of mv commands that it would make) - you can actually make the changes by running the same command without the echo once you are satisfied that it's going to do what you want.


[#26135] Thursday, June 23, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aslity

Total Points: 336
Total Questions: 133
Total Answers: 98

Location: Zimbabwe
Member since Thu, Jul 21, 2022
2 Years ago
;