How to search file based on DAY of week
The simplest way with find
is:
find / -daystart -mtime +41 -mtime -408 \
-printf "%M %n %u %g %10s %TY-%Tm-%Td %Ta %TH:%TM:%TS %h/%f\n" |
awk '($7=="Fri"){print}'
Adjust the -printf
as required, I've made it look close to ls -l
here.
%T
(and %A
%C
) let you use strftime()
formatting for timestamps, %Ta
being the day of the week. (You may need to adjust the day ranges 41 - 408, but that's really just an optimisation, you can just grep 2012
, or adjust -printf
to make it easier to grep.)
Edit: a more robust version, with some slight loss of clarity:
find / -daystart -mtime +41 -mtime -408 \
-printf "%M %n %u %g %10s %TY-%Tm-%Td %Ta %TH:%TM:%TS\0%h/%f\0\0" |
gawk 'BEGIN{RS="\0\0"; FS="[\0]"} ($1~/ Fri /) { printf $2 "\0"}' |
xargs -0 -n 1 -i ls -l "{}"
This emulates -print0
, but each line has two \0
delimited fields, the filename being the second.
Replace ls -l "{}"
at the end with whatever you need to do to the file(s). I'm explicitly using gawk
, other awks do not take so kindly to \0 bytes in RS
/FS
(updated to handle newlines in file names too).
Also, as suggested by mreithub you can use %Tu
as well as, or instead of %Ta
for a numbered weekday, a language independent option.