--- title: "Set a lifecycle rule" description: "Expire objects in a bucket after a set number of days, for the whole bucket or one prefix." content_type: "how-to" product: "object-storage" platform: "MyAccount" url: "/myaccount/object-storage/how-to/set-a-lifecycle-rule/" topic: ["protect-your-data"] relationships: {"requires":["/myaccount/object-storage/how-to/create-a-bucket/"]} --- # Set a lifecycle rule A lifecycle rule deletes objects once they reach an age you set, so old data clears itself. Expiry is the one thing it does; objects stay in the same storage until then. ## Create a rule Open the bucket's **Actions** menu and select **Lifecycle Rule**. Choose what it applies to: - **Whole Bucket** applies the rule to every object. - **On Prefix** applies it only to objects whose name starts with the prefix you enter. Set **Latest Object Versions Validity**, from 1 to 100 days, for how long a current object lasts before it expires. If the bucket has [Object Versioning](/myaccount/object-storage/how-to/turn-on-object-versioning/) on, you can also set **Previous Object Versions Validity** for how long an older version lasts. Click **Save**. ## Check the rule on the Bucket Lifecycle tab Open the bucket's **Bucket Lifecycle** tab. Your rule is in the list with the prefix it covers, or the whole bucket, and the number of days you set. From then on, objects it covers are deleted once they are older than that, so check the prefix and the days before any object reaches that age. ## Manage existing rules To change a rule, delete it from its **Actions** menu on the **Bucket Lifecycle** tab and add a new one. A bucket can have as many rules as you need, for example a short expiry for a `tmp/` prefix and a longer one for `logs/`. To keep earlier copies when an object is overwritten, see [Turn on Object Versioning](/myaccount/object-storage/how-to/turn-on-object-versioning/).