#!/bin/bash pth="$1" ((keep=45)) if [[ "X$pth" == 'X' ]] then echo "usage: $0 path" exit fi cd ${pth} pwd cnt=$(ls -1 | grep -v 'dirvish' | grep -v current | grep -v lost+found | grep -v mlocate | wc -l) ((n = cnt - keep)) ls -1 | grep -v 'dirvish' | grep -v current | grep -v lost+found | grep -v mlocate | head -${n} | while read dir do echo $dir file="${dir}/summary" line=$(grep '^Expire:' ${file}) newline="Expire: +45 days == 2014-05-08 03:30:39" echo "mv -f ${file} ${file}.tmp" mv -f ${file} ${file}.tmp echo "cat ${file}.tmp | sed \"s/${line}/${newline}/\" \> ${file}" cat ${file}.tmp | sed "s/${line}/${newline}/" > ${file} done