how to rename a list of .jpg pictures

Asked by Mart

The rename function only operates with one jpg picture at a time. I wish to be able to highlight a list of files and rename these in one operation.

Question information

English Edit question
Ubuntu nautilus Edit question
No assignee Edit question
Solved by:
Dave Gilbert
Last query:
Last reply:
Revision history for this message
Dave Gilbert (ubuntu-treblig) said :

Can you give an example of what the names are like at the moment and how you want them to be? Obviously you don't want them all to have the same name after the rename!

Revision history for this message
Alphax (alphax) said :

What are you trying to rename them to? Not everything is doable using a GUI; you may have to jump into a terminal to do what you want. If you wanted to rename all .jpg files to .jpeg, open up a terminal with Bash in it and run:

for i in *.jpg; do mv ${i} `echo ${i} | sed -r 's/(.*)\.jpg/\1.jpeg/'`; done

Of course, your best bet of getting a precise answer is to ask a precise question...

Revision history for this message
Jens Dreger (jens-dreger) said :

Perl contains a usefull rename util:

root@edgy:~> rename
Usage: rename [-v] [-n] [-f] perlexpr [filenames]

You can do all kinds of renaming. See 'man rename'. Some examples:

* Rename .jpg to .jpeg:
root@edgy:~> touch image.jpg filename\ with\ space.jpg
root@edgy:~> rename -n 's/jpg$/jpeg/' *.jpg
filename with space.jpg renamed as filename with space.jpeg
image.jpg renamed as image.jpeg

(in contrast to the solution given above this is save for filenames with spaces)

* Spaces to underscores:
root@edgy:~> rename -n 's/ /_/g' *.jpg
filename with space.jpg renamed as filename_with_space.jpg

* Renumber names:
root@edgy:~> rename -n 's/^(\d+)(.*)/sprintf("%03d",$1).$2/e' *jpg
10_blah.jpg renamed as 010_blah.jpg
1_blah.jpg renamed as 001_blah.jpg

* Append filesize (not very useful...):
root@edgy:~> rename -n 's/$/",size=".(-s)/e' *.jpg
cimg0001.jpg renamed as cimg0001.jpg,size=877072
cimg0002.jpg renamed as cimg0002.jpg,size=883343
cimg0003.jpg renamed as cimg0003.jpg,size=874881

Another nice trick for digital photos is using jhead to put the date from the exif header into the filename:

root@edgy:~> jhead -n%Y%m%d-%H%M%S cimg000*
cimg0001.jpg --> 20050622-221526.jpg
cimg0002.jpg --> 20050622-221535.jpg
cimg0003.jpg --> 20050622-221551.jpg

Revision history for this message
williamts99 (williamts99) said :

Though this does sound like it would be a good feature request for gnome. It is available in Windows, is it available with KDE?

Revision history for this message
Andrew Chadwick (achadwick) said :

Another possibility is to install the "Bulk Rename" tool from the "thunar" package (Applications>Add/Remove...) , and then run Applications>System Tools>Bulk Rename. You can then drag the files you want to rename from File Manager (nautilus) into Bulk Rename and do quite a few simple filename operations from there: prefixing or suffixing, numbering, patterns and regular expressions.

If we're not on the right track, it'd be really helpful if you could clarify exactly what you're trying to achieve here: could you give us some examples of the kind of renaming you're trying to do?

Hope this is OK. Please consider closing this ticket if you feel your question has been answered by someone: see for details of how to do that.

Revision history for this message
Mart (zammitms) said :

Thank you.
 The 'Bulk Rename' tool is what i was after.

Revision history for this message
PeteJ (vendors07) said :

Inspired by

find . -user xyz | ( while read a;do l[${#l[@]}]="$a"; done; chown abc "${l[@]}" )

found at:

I built this:

find . -name "* *" -print | ( while read a; do export b=`echo $a | sed 's/ //g'` ; mv -i "$a" $b ; done )

which drills down the current directory tree and removes spaces from filenames. This could be extended I think fairly simply to instead replace spaces and/or remove or replace other special characters by tweaking the sed substitution.