Rename to sequential order

Here are multiple ways to rename files inside a folder to a sequential numbers

1- In one line :

ls | cat -n | while read n f; do mv "$f" "$n.extension"; done

you can also use ls -uT to sort files by creation date

2- With the 'rename' command

rename -N 0001 -X 's/.*/$N/' *.jpg

3- With a script

for i in *.jpg; do
   new=$(printf "%04d.jpg" "$a") #04 pad to length of 4
   mv -i -- "$i" "$new"
   let a=a+1

Laissez un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors