Terminal: Rename multiple files to be in numerical order [duplicate]
By James Williams
I have a lot of files that I need to rename in numerical order. So what I have is this
Getting Started 1.jpg
Getting Started 10.jpg
Getting Started 100.jpg
Getting Started 101.jpg
Getting Started 102.jpgand what I want to do is rename them so that they are ordered like
Getting Started 001.jpg
Getting Started 002.jpg
Getting Started 003.jpg
Getting Started 004.jpgis there a simple way to do this?
02 Answers
Create a .bsh file inside the directory in which your images are stored and paste the below code :
#!/bin/bash
count=1
for file in *.jpg
do new=$(printf "Getting Started %03d.jpg" "$count") mv -- "$file" "$new" (( count++ ))
doneOpen a Terminal and navigate to the directory in which your script is stored.
To change the permissions of the script :
chmod +x <filename>.bshTo execute the script :
bash <filename>.bshNote:%03d sets pad to length of 3
The simplest way to do it is to use a purpose-made application, such as PyRenamer
sudo apt-get install pyrenamer