W
W
Welaurs2017-08-11 23:59:52
linux
Welaurs, 2017-08-11 23:59:52

Linux shell: how to delete files older than a certain date?

Good day. If a script that automatically backups the database to a specific folder. How can I make sure that backups older than, say, 1 day, are deleted from the folder?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Saboteur, 2017-08-12
@Welaurs

find /path/to/files/* -mtime +1 -delete
At the same time, the nuance
-mtime +1
modified more than 1 day ago
-mtime 1
modified one day ago (today and the day before yesterday will not be affected)
instead of -delete, you can not write anything for a start, it will display what it finds on the screen to make sure everything is ok.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question