Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
script to get the files created on recent saturday and sunday irrespective on the day on which we run

To be accurate, Unix does not have a file creation time - just a file modification time. The modification time is changed each time a file is written to. Any user with write permission on a file can change the modification file with the touch command.The best you can hope for is a script showing the modification time of last Sat or Sun. Can you live with that?

I need a script for getting the list of files showing the modification time of last Sat or Sun.
please help me out

What you are asking for is not easy. You have to subtract backward thru the days until you hit Sunday and Saturday thus endding the loop.
Also, there are special condtions for the end of the month and end of the year. I didn't test them and I am leaving the leap year check to you::
#!/bin/ksh typeset -i mnum get_month_no() { case $1 in "Jan") echo "1";; "Feb") echo "2";; "Mar") echo "3";; "Apr") echo "4";; "May") echo "5";; "Jun") echo "6";; "Jul") echo "7";; "Aug") echo "8";; "Sep") echo "9";; "Oct") echo "10";; "Nov") echo "11";; "Dec") echo "12";; *) echo "error";; esac } # This function returns the day of week where # 0 = sunday, 1 = monday, ... 6 = saturday # This algorithm is from Mike Keith's World of Words & Numbers: # <a href="http://users.aol.com/s6sj7gt/mikecal.htm" target="_blank">http://users.aol.com/s6sj7gt/mikeca...</a> # arguments: $1 = month, $2 = day, $3 = year in format YYYY get_dow() { # [.] means to truncate downward to the nearest integer # dayofweek=([23m/9] + d + 4 + y + [z/4] - [z/100] + [z/400] - 2 (if m >= 3)) mod 7 typeset -i DOW typeset -i z typeset -i multpr if [ $1 -lt 3 ] then # year determination z=$(($3-1)) else z=$3 fi if [ $1 -ge 3 ] then # set the multiplier multpr=2 else multpr=0 fi DOW=$(( ((23 * $1/9) + $2 + 4 + $3 + ($z/4) - ($z/100) + ($z/400) - $multpr) % 7)) echo $DOW } mnum=$(date '+%m') day=$(date '+%d') year=$(date '+%Y') sat_day=0 sun_day=0 # find the previous saturday while true do dow_num=$(get_dow $mnum $day $year) if [[ $dow_num = 0 ]] then # sunday sun_day=$day fi if [[ $dow_num = 6 ]] then # quit if it's saturday sat_day=$day break fi ((day-=1)) if [[ $day = 0 ]] then # previous month UNTESTED ((mnum-=1)) if [[ $mnum = 0 ]] then # Jan, UNTESTED mnum=12 ((year-=1)) day=31 else case "$mnum" in 9,4,6,11) day=30;; 1,3,5,7,8,9,10) day=31;; 2) day=28;; # NO LEAP YEAR CHECK esac fi fi done # echo "Sat is: $sat_day " # echo "Sun is: $sun_day" ls -l |while read f1 f2 f3 f4 f5 fmon fday f8 f9 do nm=$(get_month_no $fmon) if [[ ($nm = $mnum) && ($sat_day = $fday) ]] then echo "File $f9 is on saturday, $sat_day" fi if [[ ($nm = $mnum) && ($sun_day = $fday) ]] then echo "File $f9 is on sunday, $sun_day" fi done

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |