I want to rename all files in a certain directory. Renaming them to their date of creation.
So if my file is Image1.jpg, it should rename into something like "Jan 16 12:09:42 2011.jpg"
I want to do this through command line. I've been trying:
stat -f %SB Image0100.jpg But how can I combine this with mv command? And how will I iterate stat and mv through the whole files?
Or are there simple ways to rename all files with their date creation?
You can batch rename images in Windows by selecting (Shift+click or Ctrl+click to select several files; Ctrl+A to select all) and pressing right-click > "Rename". Your file names will look like image (1), image (2), image (3) etc.
jhead -n DSCN0382.JPG DSCN0382.JPG --> 0408-150734.jpg any strftime argument can be given as well:
jhead -n%Y%m%d-%H%M%S *.jpg This will rename files matched by *.jpg in the format YYYYMMDD-HHMMSS
jhead -n%Y%m%d-%H%M%S DSCN0382.JPG DSCN0382.JPG --> 20120408-150734.jpg see also the man page for lots of other cool options. You can for instance correct (shift) the EXIF date. This is very handy when merging files from different camera's when some camera's have an incorrect time set.
If you're working with JPG that contains EXIF data (ie. from digital camera), then you can use following to get the creation date instead of stat.
exif -t 0x9003 -m Image0100.jpg Per request, here's the command and output. A couple of points to note:
dst is valid before doing the rest of commands. for i in *.jpg; do dst=$(exif -t 0x9003 -m $i ) && dst_esc=$(echo $dst | sed 's/ /-/g' ) && echo mv $i $dst_esc.jpg done '12379632.jpg' does not contain tag 'DateTimeOriginal'. mv 15084688.jpg 2003:02:28-21:48:54.jpg mv 15136312.jpg 2003:03:01-10:36:05.jpg mv 15137960.jpg 2003:03:01-10:36:38.jpg mv 15140744.jpg 2003:03:01-10:37:46.jpg
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With