Can I create a cron to delete files with retroactive dates?

0

See my need, I have a cron that runs every night and creates a file_ddmmaaaa.backup on the Linux Kubuntu server, it happens that the hard disk is filling since this backup file has in average 500MB, how to create a cron that deletes files a date earlier than one week from the current date?

I've been thinking about how to do this but I do not handle a lot of cron and how could I put variables in cron, maybe the solution is script, but rs, I'm also very good at script.

The delete script would be roughly

delete /folder/file.backup

Where would * file be with previous dates

    
asked by anonymous 16.12.2017 / 16:13

1 answer

0

You can use the find command to search for the old files and then remove them.

find /path/to -type f -mtime +7 -print0 | xargs -0 rm --

In this way, the command will list all the files that were modified at least 7 days ago.

You can replace the -mtime parameter with -atime or -ctime , which checks the date of the last time the file was accessed or changed respectively.

    
16.12.2017 / 23:51