S
S
SpeakLive912018-10-26 19:40:35
bash
SpeakLive91, 2018-10-26 19:40:35

How to rename the names of pictures in the correct sequence, starting from 1, depending on the date of creation of the original picture?

Hello. At this stage, the following code is available:

#!/bin/sh
p=1;
j=0;
wget $(sed "s/;/\n/g" url.txt) -P $p;
for i in $p/*.jpg; do
    let j+=1;
    mv $i $p/$j.jpg ;
done
sleep 1
exit 1

The essence of the script: it takes image links in the form link1.jpg; link2.jpg from the url.txt file and pumps them to the $p=1 directory, which is created in the folder where the script was launched from. After that, the images already downloaded to the server are renamed according to this cycle:
for i in $p/*.jpg; do
    let j+=1;
    mv $i $p/$j.jpg ;
done

Files are renamed from 1 to n-number of images.jpg and moved to the $p directory.
In folder 1/ there is a list with ready-made photos.
Now let's move on to my problem. The fact is that when the pictures are renamed, their order will change relative to the date of creation of the original (not renamed pictures). I need it to rename the pictures in the script in the same order as in the original relative to the date the file was created. How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2018-10-26
@SpeakLive91

I need it to rename the pictures in the script in the same order as in the original relative to the file creation date. How to do it?

To renumber files in ascending order of their last modification time:
ls -rt $p/*.jpg | while read i ; do
    let j+=1;
    mv "$i" "$p/$j.jpg" ;
done

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question