find $HOME -maxdepth 3 -type f -atime -7 \( -name '*.txt' -or -name '*.md' \)
∞
Find .txt
and .md
files that were accessed within the past week.
The -atime -7
controls the time here. It can also be used to find
files accessed more than a week ago (-atime +7
), or exactly a week
ago -atime 7
.
The other interesting part are the parentheses, which are used to
group the -name
options together, so that -or
works only on
those two. If the parentheses were not used, -or
would have
either matched everything before it or everything after it.
-maxdepth 3
is used so that the search space is small enough.
With it enabled, the command completes almost instantaneously:
0.07s user 0.06s system 98% cpu 0.139 total
Whereas -maxdepth 4
is already much slower.
0.31s user 0.97s system 37% cpu 3.403 total
This works on my system because my notes are in relatively high-up directories.
Update:
Instead of the command above, I now use one that sorts the files by access time and returns all files it finds, not only the more recent ones:
ls -1t $(find $HOME -maxdepth 2 -type f \( -name '*.txt' -or -name '*.md' \) \! -path "$HOME/.*")
This runs as a cronjob and its output is redirected into $HOME/.recent.txt
,
where it is then read by Emacs.