Linux/Ubuntu: Delete files older than 30 days via SSH

In this article, I explain how you can delete files in Linux/Ubuntu that are older than 30 days. This is especially useful if you create automated backups and want to delete them after 30 days.

The 30 days is the period when the file was last modified.

Delete files older than 30 days #

You can use the find command to find all files older than X days. You can also delete the found files directly with the command.

First, you should list all files that are older than 30 days. To do this, we look in the /opt/backup directory for all files that were last modified +30 days ago.

find /opt/backup -type f -mtime +30

Note: You can of course adapt the directory to your needs. Important: In case of an incorrect call, the deletion of files can lead to a failure of the system.

Now check the list that is displayed. Once you are satisfied with it, you can delete the found files with the following command.

find /opt/backup -type f -mtime +30 -delete
Hier klicken, um den Beitrag zu bewerten
[Gesamt: 0 Durchschnitt: 0]

Leave A Comment

Title