0

I have a directory that contain logs for each day. Each directory is formated with this name pattern 2012_07_01 , 2012_07_02.

What I want is to check from a given $startdate and a $enddate, and see if between any of that time from the start and enddate variables exists empty folders on the return list of the search. If that is the case then I remove the empty folders from my list of returned values.

AS for the ones that have files inside them I want to search each one of them for the $startdate and $enddate values. If they exist in any of the directories then I want the script to return me with that list of filenames.

January
  • 16,320
  • 6
  • 52
  • 74
drd0sPy
  • 63
  • 9
  • This question has some room for improvement -- Do use punctuation and appropriate capitalisation, and do share what you're tried so far. – Shawn Chin Nov 09 '12 at 11:55
  • 1
    Do the directories have correct time stamps? It would be easier to do it with `find -ctime`. – January Nov 09 '12 at 12:24
  • hmm i'm not quite sure what you mean but correct by what i can tell you is all in the all the directories have that name from 2012_07_01 to today date 2012_11_09, and its a folder that is created for each day ,manually ,by another person that make sure that all the log files from that day have the correct size and quality and content , then that person move it to the correct folder in this case the logs for each day inside the day they were created. So i guess the answer is yes they have the correct time stamp – drd0sPy Nov 09 '12 at 12:33
  • can you define the -ctime for the startdate variable? – drd0sPy Nov 09 '12 at 15:26

1 Answers1

1

Here is an idea:

for dir in `ls | sort | sed -n "/$startdate/,/$enddate/p"` ; do
  if [ `ls $dir | wc -l` -gt 0 ] ; then
    ls $dir
  else
    rmdir $dir
  fi
done

Also, note that rmdir * will only remove empty directories.

January
  • 16,320
  • 6
  • 52
  • 74