First, put your find ...
command in a bash
script, and call that script from your crontab
. If you have an encrypted home directory (cat /home/.ecryptfs/$USER/.ecryptfs/Private.mnt
) you'll have to store your script outside your $HOME
directory tree. Keeping a command in crontab
makes configuring, logging and debugging harder, and the crontab
command parser isn't as clever as bash
's.
Second, always, Always, ALWAYS test find
with -print
, and get it to work, before considering -delete
.
Third, the find
test "-mtime 29
" is telling find
"Find the file's mtime
, and return True
if it's equal to 29
. You should use -mtime +29
, which find
sees as "more than 29
", which is what you want. From man find
:
Numeric arguments can be specified as
+n for greater than n,
-n for less than n,
n for exactly n.
Fourth, be sure you have Write access to the directories in /home/USER/DIRECTORY1/DIRECTORY2/
.
Fifth, do you mean /home/USER/DIRECTORY1/DIRECTORY2/
or /home/$USER/DIRECTORY1/DIRECTORY2/
? If $USER
is for the user's userid, you have a problem: cron
doesn't define $USER
in the runtime enviroinment. It does define $HOME
, so you could use $HOME/DIRECTORY1/DIRECTORY2
.