mc rm — MinIO Object Storage for Linux (original) (raw)

Table of Contents

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.

For more information on how MinIO performs DELETE actions on objects, see Object Deletion.

Important

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

EXAMPLE

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

mc rm --recursive myminio/mydata

SYNTAX

The command has the following syntax:

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

Copy the example to a text editor and modify as-needed before running the command in the terminal/shell.

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 of a MinIO deployment 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 --recursive and--force arguments. For example:

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

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

Consider first running the command with the--dry-run 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 underGOVERNANCE object locking.

--dangerous

Optional

Allows running mc rm when the ALIASspecifies the root (all buckets) on the MinIO deployment.

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

Consider first running the command with the --dry-run to validate the scope of the site-wide delete operation.

Warning

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

--dry-run

Optional

Outputs the results of a command without actually removing any files. Use this flag to test that your command configuration removes only the objects you wish to remove.

--force

Optional

Allows running mc rm with any of the following arguments:

--incomplete, I

Optional

Remove incomplete uploads for the specified object.

If any ALIAS specifies a bucket, you must also specify --recursiveand --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-currentobject versions from the specified ALIAS.

This option has no effect on buckets withoutversioning enabled.

--older-than

Optional

Remove object(s) older than the specified time limit. Specify a string in #d#h#m#s format. For example: --older-than 1d2h3m4s.

Defaults to 0 (all objects).

--recursive, r

Optional

Recursively remove the contents of each ALIASbucket or bucket prefix.

If specifying --recursive, you must also specify --force.

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

Consider first running the command with the--dry-run flag to validate the scope of the recursive delete operation.

Mutually exclusive with mc rm --version-id

--rewind

Optional

Directs mc rm to operate only on the object version(s) that existed at specified point-in-time.

--rewind requires that the specified ALIAS be an S3-compatible service that supports Bucket Versioning. For MinIO deployments, usemc version to enable or disable bucket versioning.

--stdin

Optional

Read object names or buckets from STDIN.

--versions

Optional

Directs mc rm to operate on all object versions that exist in the bucket.

--versions requires that the specified ALIAS be an S3-compatible service that supports Bucket Versioning. For MinIO deployments, usemc version to enable or disable bucket versioning.

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

--version-id, vid

Optional

Directs mc rm to operate only on the specified object version.

--version-id requires that the specified ALIAS be an S3-compatible service that supports Bucket Versioning. For MinIO deployments, usemc version to enable or disable bucket versioning.

Mutually exclusive with any of the following flags:

Global Flags

This command supports any of the global flags.

Examples

Remove a Single Object

Recursively Remove a Bucket’s Contents

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

mc rm --recursive --force ALIAS/PATH

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 --incomplete option to remove incomplete upload files for an object.

mc rm --incomplete --recursive --force ALIAS/PATH

Roll Object Back To Previous Version

Use mc rm with --versions and--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

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 asdefault object lock settings.

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

MinIO Trims Empty Prefixes on Object Removal

mc rm relies on the mc removal API for deleting objects. As part of removing the last object in a bucket prefix, mc also recursively removes each empty part of the prefix up to the bucket root. mc only applies the recursive removal to prefixes created implicitly as part of object write operations - that is, the prefix was not created using an explicit directory creation command such as mc mb.

For example, consider a bucket photos with the following object prefixes:

photos/NYE21 is the only prefix explicitly created using mc mb. All other prefixes were implicitly created as part of writing the object located at that prefix.

If an mc command removes myphoto.jpg, the removal API automatically trims the empty /january prefix. If a subsequent mc command removesmyotherphoto.jpg, the removal API automatically trims both the /februaryprefix and the now-empty /2021 prefix. If an mc command removesNewYears.jpg, the /NYE21 prefix remains in place since it was_explicitly_ created.

If using mc rm for operations on a filesystem, mc applies this same behavior by recursively trimming empty directory paths up to the root. However, the mc remove API cannot distinguish between an explicitly created directory path and an implicitly created one. If mc rm deletes the last object at a filesystem path, mc recursively deletes all empty directories within that path up to the root as part of the removal operation.

Delete Operations in Versioned Buckets

MinIO supports keeping multiple versions of an object in a single bucket. Deleting 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.

Changed in version mc: RELEASE.2023-03-20T17-17-53Z

The output shows the modification time of versioned files. When used with --dry-run, this can help confirm that you selected the correct object(s) for removal.

S3 Compatibility

The mc commandline tool is built for compatibility with the AWS S3 API and is tested with MinIO and AWS S3 for expected functionality and behavior.

MinIO provides no guarantees for other S3-compatible services, as their S3 API implementation is unknown and therefore unsupported. While mccommands may work as documented, any such usage is at your own risk.