4

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

5

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.

  • This is a great solution (+1) but why did you revert my edit? This will name the first file 000.avi and the OP wanted 001.avi – terdon Apr 8 '14 at 16:28
  • Apologies - I didn't intend to revert your edit - I think we just edited at the same time (I added -- to the mv) – steeldriver Apr 8 '14 at 16:35
  • Ah, yes and I wish I could give you +2 for that (and for correct quoting). No need to apologize, it's your post! I'd still set i=1 though, the variable does not seem to be incremented as expected. – terdon Apr 8 '14 at 16:39
  • 2
    Nice feature of this script btw: If you use it as: rename.sh * if will just rename alfabetically,.. but if your use it: rename.sh *.txt *.jpg *.avi it will first number through all the txt and than the jpg etc. – bacon Apr 8 '14 at 16:42
  • @bacon Oh, I didn't pick up on that on first reading! Nice work @steeldriver! – Madivad Nov 21 '15 at 11:23
1

GwenRename is a series renaming tool. It was created as an external tool for GwenView, the image viewer for KDE, but can also be used from Konkueror. As that, the files to be renamed are passed to it as command line parameters, and there is no other way to load files into it.

The main goal is to have a batch renaming tool that's easy and light enough for every day use. If you are looking for a more compound and featured renaming tool, you should have a look at Dominik Seichter's KRename.

gwenRename

pyRenamer is a mass file renamer, written in PyGTK.

pyRenamer

  • Both applications can be downloaded through Software-Center.
1

Found another rather short solution:

  n=0; for f in * ; do mv "$f" "$n.${f/*./}"; n=$((n+1)); done 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.