Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Actually I need to search for files and folder that were created in 2012 on Friday of every month.

I did some attempts using the find command but it didn't work.

share|improve this question
up vote 5 down vote accepted

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.

share|improve this answer
Note that something like this will also show files with names containing Fri, even if they were never touched on a Friday. I guess you could work around that with a separator, splitting and checking each part. Still, it's a decent approximation using commonly available tools in a semi-readable manner, so +1. – Michael Kjörling Feb 11 '13 at 10:45
So, to simplify this, I'd use: find /mnt/music/Datenbank -mtime +41 -mtime -408 -printf "%Ta %p\n"|grep ^Fri|sed 's/^Fri //'. You might need to prepend a LC_ALL=C to make sure the week day is english – mreithub Feb 11 '13 at 10:48
@MichaelKjörling Yep, fixed, thanks! – mr.spuratic Feb 11 '13 at 10:48
I like it even better now, but can't upvote twice unfortunately :) @mreithub's solution in comment is good too. – Michael Kjörling Feb 11 '13 at 10:51
also note you could use `... -printf %Tu %p\n"|grep ^5|sed 's/^5 //' to make it language-independent (but a little less readable... – mreithub Feb 11 '13 at 10:55

With gnu tools:

find . -exec bash -c '[[ $(date -r "$0" +%u%Y) = "52012" ]]' {} \; -print

the files/directories names are -printed only if the previous -exec returned true, that is if the mtime as reported by date -r in the specified format (%u%Y) is 52012

Or, if you prefer a zsh-only solution (it's quite similar, the e-string selects only those files/directories for which the expression inside the quotes returns true):

zmodload zsh/stat
print -rl -- **/*(De_'[[ $(zstat -F "%u%Y" +mtime -- $REPLY) = "52012" ]]'_)
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.