Filtering Filenames with bash

Posted by Stefan Liebenberg on Stack Overflow See other posts from Stack Overflow or by Stefan Liebenberg
Published on 2010-03-14T17:46:48Z Indexed on 2010/03/14 17:55 UTC
Read the original article Hit count: 348

Filed under:
|

I have a directory full of log files in the form

${name}.log.${year}{month}${day}

such that they look like this:

logs/
  production.log.20100314
  production.log.20100321
  production.log.20100328
  production.log.20100403
  production.log.20100410
  ...
  production.log.20100314
  production.log.old

I'd like to use a bash script to filter out all the logs older than x amount of month's and dump it into *.log.old

X=6  #months

LIST=*.log.*;
for file in LIST; do
  is_older = file_is_older_than_months( ${file}, ${X} );
  if is_older; then
    cat ${c} >> production.log.old;
    rm ${c};
  fi
done;

How can I get all the files older than x months? and... How can I avoid that *.log.old file is included in the LIST attribute?

Thank you
Stefan

© Stack Overflow or respective owner

Related posts about shell

Related posts about bash