User Tools

Site Tools


bash:one_liners:find_last_day_of_the_month

I needed to find the date of the last Sunday in the current month in relation to a backup script. This is the result:

ncal -h 2>&1 | awk '/Su/ {print $(NF)}'

Change “Su” to “Mo” “Tu” or any other day of the week to find the last of that day in the current month

Finding the amount of days can be done like this:

date -d "`date +%m`/1 + 1 month - 1 day" "+%d";

Finding out what day the last date is can be done like this:

date -d "`date +%m`/1 + 1 month - 1 day" "+%a";

Check out the man page for date, it's got a lot of goodies in it :)

bash/one_liners/find_last_day_of_the_month.txt · Last modified: 2015/08/15 22:56 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki