1
0
mirror of https://github.com/minio/docs.git synced 2025-04-27 18:36:56 +03:00
2022-09-16 16:40:20 -04:00

12 KiB

mc rm

minio

Table of Contents

mc rm

Syntax

The mc rm command removes objects from a bucket on a MinIO deployment. To completely remove a bucket, use mc rb instead.

You can also use mc rm against the local filesystem to produce similar results to the rm commandline tool.

Important

mc rm supports removing multiple objects or files in a single command. Consider using the ~mc rm --fake option to validate that the operation targets only the desired objects/files.

EXAMPLE

The following command removes multiple objects from the mydata bucket on the myminio MinIO deployment:

mc rm --recursive myminio/mydata

SYNTAX

The command has the following syntax:

mc [GLOBALFLAGS] rm  \
                 [--bypass]               \
                 [--dangerous]            \
                 [--fake]                 \
                 [--force]*               \
                 [--incomplete]           \
                 [--newer-than "string"]  \
                 [--non-current]          \
                 [--older-than "string"]  \
                 [--recursive]            \
                 [--rewind "string"]      \
                 [--stdin]                \
                 [--version-id "string"]* \
                 [--versions]             \
                 ALIAS [ALIAS ...]

mc rm --force is required by multiple parameters. mc rm --version-id is mutually exclusive with multiple parameters. See the reference documentation for more information.

Parameters

ALIAS

Required The alias <alias> of a MinIO deplyment and the full path to the object to remove. For example:

mc rm play/mybucket/object.txt

You can specify multiple objects on the same or different MinIO deployments. For example:

mc rm play/mybucket/object.txt play/mybucket/otherobject.txt

If specifying the path to a bucket or bucket prefix, you must also specify the ~mc rm --recursive and ~mc rm --force arguments. For example:

mc rm --recursive --force play/mybucket/

mc rm --recursive --force play/mybucket/myprefix/

Consider first running the command with the ~mc rm --fake flag to validate the scope of the recursive delete operation.

For removing a file from a local filesystem, specify the full path to that file:

mc rm ~/data/myoldobject.txt

--bypass

Optional Allows removing an object held under GOVERNANCE <minio-object-locking-governance> object locking.

--dangerous

Optional Allows running mc rm when the ~mc rm ALIAS specifies the root (all buckets) on the MinIO deployment.

When combined with ~mc rm --versions, this flag directs mc rm to permanently remove all objects and versions from the ALIAS target.

Consider first running the command with the ~mc rm --fake to validate the scope of the site-wide delete operation.

Warning

Running mc rm --dangerous with the ~mc rm --versions flag is irreversible. Exercise all possible due diligence in ensuring the command applies to only the desired ALIAS targets prior to execution.

--encrypt-key

Optional The encryption key to use for performing Server-Side Encryption with Client Keys (SSE-C). Specify comma seperated key-value pairs as KEY=VALUE,....

  • For KEY, specify the S3-compatible service alias <mc alias> and full path to the bucket, including any bucket prefixes. Separate the alias and bucket path with a forward slash \. For example, play/mybucket
  • For VALUE, specify the data key to use for encryption object(s) in the bucket or bucket prefix specified to KEY.

~mc rm --encrypt-key can use the MC_ENCRYPT_KEY environment variable for populating the list of encryption key-value pairs as an alternative to specifying them on the command line.

--fake

Optional Perform a fake remove operation. Use this operation to perform validate that the mc rm operation will only remove the desired objects or buckets.

--force

Optional Allows running mc rm with any of the following arguments:

  • ~mc rm --recursive
  • ~mc rm --versions
  • ~mc rm --stdin

--incomplete, I

Optional Remove incomplete uploads for the specified object.

If any ~mc rm ALIAS specifies a bucket, you must also specify ~mc rm --recursive and ~mc rm --force.

--newer-than

Optional Remove object(s) newer than the specified number of days. Specify a string in #d#hh#mm#ss format. For example: --newer-than 1d2hh3mm4ss

Defaults to 0 (all objects).

--non-current

Optional Removes all non-current <minio-bucket-versioning-delete> object versions from the specified ~mc rm ALIAS.

This option has no effect on buckets without versioning <minio-bucket-versioning> enabled.

--older-than

Optional Remove object(s) older than the specified time limit. Specify a string in #d#hh#mm#ss format. For example: --older-than 1d2hh3mm4ss.

Defaults to 0 (all objects).

--recursive, r

Optional Recursively remove the contents of each ~mc rm ALIAS bucket or bucket prefix.

If specifying ~mc rm --recursive, you must also specify ~mc rm --force.

For buckets with versioning <minio-bucket-versioning> enabled, this option by default produces a delete marker for each removed object. Include the ~mc rm --versions flag to recursively remove all objects and object versions from the bucket.

Consider first running the command with the ~mc rm --fake flag to validate the scope of the recursive delete operation.

Mutually exclusive with mc rm --version-id

--rewind

--stdin

Optional Read object names or buckets from STDIN.

--versions

Use ~mc rm --versions and ~mc rm --rewind together to remove all object versions which existed at a specific point in time.

--version-id, vid

Mutually exclusive with any of the following flags:

  • ~mc rm --versions
  • ~mc rm --rewind
  • ~mc rm --recursive

Global Flags

Examples

Remove a Single Object

mc rm ALIAS/PATH
  • Replace ALIAS <mc rm ALIAS> with the alias <mc alias> of a configured S3-compatible service.
  • Replace PATH <mc rm ALIAS> with the path to the object.

Recursively Remove a Bucket's Contents

Use mc rm with the ~mc rm --recursive and ~mc rm --force options to recursively remove a bucket's contents.

mc rm --recursive --force ALIAS/PATH
  • Replace ALIAS <mc rm ALIAS> with the alias <mc alias> of a configured S3-compatible service.
  • Replace PATH <mc rm ALIAS> with the path to the bucket.

This operation does not remove the bucket. Use mc rb to remove the bucket along with all contents and associated configurations.

Remove All Incomplete Upload Files for an Object

Use mc rm with the ~mc rm --incomplete option to remove incomplete upload files for an object.

mc rm --recursive --force ALIAS/PATH
  • Replace ALIAS <mc rm ALIAS> with the alias <mc alias> of a configured S3-compatible service.
  • Replace PATH <mc rm ALIAS> with the path to the object.

Removing incomplete upload files prevents resuming the upload using the mc mv --continue or mc cp --continue commands.

Roll Object Back To Previous Version

Use mc rm with ~mc rm --versions and ~mc rm --newer-than to remove all object versions newer than the specified duration of time. This effectively "rolls back" the object to its state at that time.

Important

Removing specific versions of an object is a destructive action. You cannot restore the deleted object versions.

mc rm ALIAS/PATH --versions --newer-than DURATION
  • Replace ALIAS <mc rm ALIAS> with the alias <mc alias> of a configured S3-compatible service.
  • Replace PATH <mc rm ALIAS> with the path to the object. For example, /mybucket/myobject.
  • Replace DURATION <mc rm --newer-than> with the number of days in the past from the current host time from which the operation begins removing versions of the object. For example, to remove all versions of the object created in the last 30 days, specify "30d".

Behavior

Deleting Bucket Contents

Using mc rm to remove all contents in a bucket does not delete the bucket itself. Any configurations associated to the bucket remain in place, such as default object lock settings <mc retention set --default>.

To completely remove a bucket, use mc rb instead of mc rm.

MinIO Trims Empty Prefixes on Object Removal

Delete Operations in Versioned Buckets

MinIO supports keeping multiple versions <minio-bucket-versioning> of an object in a single bucket. Deleting <minio-bucket-versioning-delete> an object in a versioned bucket results in a special DeleteMarker tombstone that marks an object as deleted while retaining all previous versions of that object.

  • To remove a specific object version from a bucket, use mc rm --version-id
  • To remove all versions of an object from a bucket, use mc rm --versions
  • To remove all non-current versions of an object from a bucket, use mc rm --non-current

S3 Compatibility