Re: Deleting x months old files
- From: "Chris F.A. Johnson" <cfajohnson@xxxxxxxxx>
- Date: Fri, 10 Aug 2007 16:17:56 -0400
On 2007-08-10, pankaj_wolfhunter@xxxxxxxxxxx wrote:
Means, if I want to delete files older than 4 months, I need to know
how many days were there in these
past 4 months (30, 31, 28).
How can I loop over these 4 months in order to come up with total
number of days?
No need to loop:
set -- 30 31 30 31 31 30 31 30 31 28 31 31 30 31 30
shift $(( 12 - ${month#0} ))
d4=$(( $1 + $2 + $3 +$4 ))
You will need to adjust for leap years; this function can tell you
whether an y given year is a leap year:
is_leap_year() { ## USAGE: is_leap_year [year]
ily_year=${1:-$( date +%Y )}
case $ily_year in
*0[48] |\
*[2468][048] |\
*[13579][26] |\
*[02468][048]00 |\
*[13579][26]00 ) _IS_LEAP_YEAR=1
return 0 ;;
*) _IS_LEAP_YEAR=0
return 1 ;;
esac
}
--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
.
- References:
- Deleting x months old files
- From: pankaj_wolfhunter@xxxxxxxxxxx
- Re: Deleting x months old files
- From: ramesh . thangamani
- Re: Deleting x months old files
- From: Joachim Schmitz
- Re: Deleting x months old files
- From: pankaj_wolfhunter@xxxxxxxxxxx
- Deleting x months old files
- Prev by Date: Re: rcp : permission denied
- Next by Date: Re: Help!
- Previous by thread: Re: Deleting x months old files
- Next by thread: Re: Deleting x months old files
- Index(es):
Relevant Pages
|