title: Bash script to set folder date to file-date-within folder
body: <p>I see I've got some minus points,..so I'll try to address this better:</p>
  
  <p>I have a linux server. (centos 6.5)</p>
  
  <pre><code>This stores all images in /mnt/usb1/images/
  
  This folder also have several subfolders.
  drwxrwxr-x     2  1033 users     4096 Jan 25  2009   /mnt/usb1/images/2014_sept_NewYork 
  drwxrwxr-x     2  1033 users     4096 Jan 25  2009   /mnt/usb1/images/2014_sept_Chicago
  ..
  
  Would be nice to set the folder date - to same date as image inside folder.
  -rwxrw-r--    1 1033 users 1753062 Mar  4  2007 IMG_0301.jpg
  -rwxrw-r--    1 1033 users 1752525 Mar  4  2007 IMG_0302.jpg
  
  Result: 
  drwxrwxr-x     2  1033 users     4096 Mar 4  2007   /mnt/usb1/images/2014_sept_NewYork 
  drwxrwxr-x     2  1033 users     4096 Mar 4  2007   /mnt/usb1/images/2014_sept_Chicago
  </code></pre>
  
  <hr>
  
  <p>My script works, but would be nice with some help/comments and improvements:</p>
  
  <pre><code>#!/bin/bash
  
  echo "" # Space at start
  echo "###############################################"
  echo "#                                             #"
  echo "# Setting folders to file modifications date  #"
  echo "#                                             #"
  echo "###############################################"
  
  echo "--- `date` ---" &gt;&gt; SetFileDate.txt
  
  while read file
  do
    touch -t $(date -r "$file" +%Y%m%d%H%M) "$(dirname "$file")"
  
  # echo date - folder/filename
    echo "`date -r \"$file\"+%Y%m%d%H%M` - \"$dirname $file\"" &gt;&gt; SetFileDate.txt
  
  done &lt; &lt;(find . \( -iname \*.JPG -o -iname \*.jpg -o -iname \*.TIF -o -iname \*.avi -o -iname \*.mkv \))
  
  echo "" &gt;&gt; SetFileDate.txt
  </code></pre>
  
  <hr>
  
  <p>Why I want this ?
  Its because at earlier point, i copied an moved file and forgot to retain permissions.. and this screwed up the folder modified time.</p>
  
  <hr>
  
  <p>..my other idea is finished (thanks to the people that contribute here on stackoverflow), it is about setting the filenames to all files inside local and subfolders.
  Check out script here: <a href="https://stackoverflow.com/questions/26963377/bash-script-to-read-exif-rename-jpg-files-and-check-output-if-file-exit-crea">Bash script to read EXIF, rename JPG files and check output if file exit -&gt; create newfile-01.jpg</a></p>