rename multiple files

Quick to answer questions about finding your way around Linux Mint as a new user.
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions use the other forums in the support section.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
Ditzyken

rename multiple files

Post by Ditzyken »

i have a folder with pictures on my computer.
they are named like:
zee.jpg
scherm.jpg
strand.jpg
toetsenbord.jpg
zon.jpg
muis.jpg
huis.jpg
trompet.jpg
boom.jpg
bank.jpg
gitaar.jpg
cola.jpg
...

they all need to be renamed like:
00001.jpg
00002.jpg
00003.jpg
00004.jpg
00005.jpg
00006.jpg
00007.jpg
00008.jpg
00009.jpg
00010.jpg
00011.jpg

How can i do this without having to do it file by file but all at once? (over 600 files that need to be renamed)
They must be renamed to filenames with 5 numbers that follow eachother (00001.jpg to 00600.jpg)

thanks
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
remoulder
Level 17
Level 17
Posts: 7621
Joined: Fri May 09, 2008 1:14 pm

Re: rename multiple files

Post by remoulder »

[Edit] your original post and add [SOLVED] once your question is resolved.

“The people are my God” stressing the factor determining man’s destiny lies within man not in anything outside man, and thereby defining man as the dominator and remoulder of the world.
ThistleWeb

Re: rename multiple files

Post by ThistleWeb »

GPrename is a powerful tool, it also allows you to rename folders.
hairybiker
Level 4
Level 4
Posts: 204
Joined: Mon Nov 03, 2008 12:16 pm

Re: rename multiple files

Post by hairybiker »

I use pyrenamer which will do all of that along with folder renaming etc. it is in the repositories.
acerimusdux
Level 5
Level 5
Posts: 635
Joined: Sat Dec 26, 2009 3:36 pm

Re: rename multiple files

Post by acerimusdux »

Honestly, the easy way is to just install the geeqie image viewer. You can select all of the files in the directory, right click, select "rename" and then the bulk rename dialog comes up, click on the "auto" tab and it's pretty easy from there. There's a "padding" setting there that you would put on "5" so that all the numbers are 5 digits with leading zeros.

Of course the 1337 way to do it is still something like:

files=`ls -v1`; let x=`ls -1|wc -l`; for ((i=1;i<x+1;i++)); do let newf=i+10000; oldf=`for ln in $files; do echo $ln; done|head -$i|tail -1`; mv $oldf $newf.jpg; done

:mrgreen:
User avatar
xenopeek
Level 25
Level 25
Posts: 29507
Joined: Wed Jul 06, 2011 3:58 am

Re: rename multiple files

Post by xenopeek »

You can do this easily with a shell script:

Code: Select all

#!/bin/bash

i=1
for FILE in `ls *.jpg`; do
	NEWNAME=$(printf '%05.5d.jpg' $i)
	echo Rename $FILE to $NEWNAME
	mv $FILE $NEWNAME
	i=$((i+1))
done
Just create an empty file in the folder where you want to rename the files, put the above in it, mark it executable (right-click, properties, permissions, allow executing as a program), and then run it. Voila.
Image
Locked

Return to “Beginner Questions”