#!/bin/bash # Figure out what the most common timestamp is in the top level of a # list of directories, and spit it out. # Why is this useful? Because the NetApp snapshot directory is listed # as... nightly.0, nightly.1, etc... and all the timestamps at that level # are identical. This script lets you quickly find which directory is # from a particular day. Also we are lazy. # requires... bash, awk, uniq, sort, tail, tr, printf # This script lives at http://www.elifulkerson.com # if we didn't get a target, go ahead and use * in the local directory if [ $# = 0 ] then dirs=`ls` else dirs=$* fi echo "Avg Date Directory"; echo "---------- ---------"; for file in $dirs; do if [ -d $file ] then ls -al $file |awk '{print $6}'|uniq -c|sort -n|tail -n 1|awk '{print $2}'|tr '\n' ' ' printf "%s \n" $file fi done;