Bash:
find ~/Downloads -ctime +14 | more
I have had code using this snippet running in a cron job and migrated it into a launchd user agent. It doesn’t work as part of that, but it also doesn’t work on the command line directly.
find ~/Downloads -ctime +14 | more
m+14
glob qualifier which can check files ages - or something like find -mtime +14
.find ~/Downloads -mtime +14 | more
That said, changing the ctime flag to “mtime” helped. Thanks very much for the suggestion!you can use zsh‘sm+14
glob qualifier which can check files ages - or something likefind -mtime +14
.
#!/bin/sh
# Searches through ~/Documents/Temporary (2-week retention)/
# and deletes all files older than 30 days while leaving the folder
# ~/Documents/Temporary (2-week retention)/Scans/ alone.
# A log file delete.log in ~/Library/Logs/ is updated with the file names
# of the deleted files.
( /usr/bin/find ~/Documents/Temporary\ \(2-week\ retention\) -mtime +30 ! -regex '.*/\..*' ! -regex '.*/Scans' -print0 | /usr/bin/xargs -0 rm -r -d ) >> ~/Library/Logs/delete.log 2>&1
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<false/>
<key>Label</key>
<string>local.cleanup-tempdocs</string>
<key>Program</key>
<string>/Users/dominik/.scripts/cleanup-tempdocs</string>
<key>RunAtLoad</key>
<true/>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>3</integer>
<key>Minute</key>
<integer>30</integer>
</dict>
<key>StartInterval</key>
<integer>86400</integer>
</dict>
</plist>
produces no output. I clearly have files older than 14 days in my Downloads folder. What could be going on?Bash:find ~/Downloads -ctime +14 | more
I have had code using this snippet running in a cron job and migrated it into a launchd user agent. It doesn’t work as part of that, but it also doesn’t work on the command line directly.
find ~/Downloads -mtime +14d
Thanks! @Slartibart beat you to that with that suggestion, though! I posted my script, which might have some more universal utility, where I am using the find command, above.I think you might have better luck with -mtime:
Bash:find ~/Downloads -mtime +14d
So, yes,
works. It still begs the question, why the ctime flag does not.Code:find ~/Downloads -mtime +14 | more
The script worked for many years. Maybe the code for “find” was brought in line with the command specification only with more recent macOS iterations. I am pretty sure, I had the same issue with Big Sur and possibly with Catalina. In other words, for many years my script was relying on a faulty implementation. Once that was fixed, the script broke.