Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 437  / 2 Years ago, thu, july 21, 2022, 2:01:18

I have a lots of images with timestamp:



cloudcam-20130825T115716Z.jpg


In the same folder I would like to create a folder named after the date(20130825) and move all the images to this folder.



Is there an easy way to do this?


More From » bash

 Answers
0

Tell me if this works (untested ;) ):



for f in `ls cloudcam-????????.jpg`; do
name=`echo "$f"|sed 's/ -.*//'`
datedir=`echo "$name"|cut -c 10-17`
dir="DestinationDirectory/$datedir/$name"
mkdir -p "$datedir"
mv "$f" "$datedir"
done


.. it should copy all jpg's beginning with cloudcam-, create a directory for position 10 to 17 of the file name, create the directory and move the file. So if you have images with another date it will put those in another directory.



Save it and make the script executable with chmod 775.



Try it first on a copy of your files.


[#29598] Thursday, July 21, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
antebrow

Total Points: 291
Total Questions: 135
Total Answers: 117

Location: New Caledonia
Member since Thu, Mar 23, 2023
1 Year ago
;