jackfalveyiv Posted April 23, 2022 Share Posted April 23, 2022 I would like to set up a cron job to delete all files and folders/directories older than 24 hours in my downloads directory. I have made a few attempts to do this but cron is proving to be a bit tougher to understand than I previously expected. I've tried a few versions of the following commands: find /mnt/user/path/path/* -type d -mtime +0 -print0 -exec rm {} + find /mnt/user/path/path/* -type f -mtime +7 -print0 | xargs -0 rm find /mnt/user/path/path/* -mtime -1 -ls -exec rm -d {} + find /mnt/user/path/path/* -mtime -1 -ls -exec rmdir -f {} + I'm finding varying degrees of success, but essentially the downloads folder is broken into a few subdirectories. I want to clean out those subdirectories of all files and folders older than 24 hours on a weekly scheduled job. I have not been able to get this working the way I want. I have run a combination of these scripts with some different options enabled, but I'm looking for one script to do what I need. Does anyone have a better example of what I'm trying to accomplish? Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.