Sample Header Ad - 728x90

Bash script - check if any files changed recently

1 vote
4 answers
1466 views
I am writing a script which needs to check if any of the files in a given directory have been modified recently. I thought I could simply use find, however it reports success even if it doesn't find a match:
$ touch afile
$ find . -mtime -1 -iname ????*
./afile
$ echo $?
0
$ find . -mtime +1 -iname ????*
$ echo $?
0
(I'm just using the iname predicate to exclude '.' here - but same behaviour with -type f) I would prefer not to have to parse the output of ls as this can be temperamental . Using test -n "$(find . -mtime -1 -iname ????*)" seems to give the desired result but doesn't strike me as a particularly elegant solution. I don't need to know which files have been modified - only if ANY have changed recently (where "recently" will usually be 1 day). Is there a better way to do this? (searching Google, I just get lots of SEO crap on how to execute a simple find)
Asked by symcbean (6301 rep)
Jan 4, 2024, 11:22 AM
Last activity: Jan 8, 2024, 01:50 AM