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.
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-run
option to validate that the operation targets only the desired objects/files.
The following command removes multiple objects from the
mydata bucket on the myminio MinIO deployment:
mc rm --recursive myminio/mydata
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 ...]
Brackets
[]indicate optional parameters.Parameters sharing a line are mutually dependent.
Parameters separated using the pipe
|operator are mutually exclusive.
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
--recursiveand--forcearguments. For example:mc rm --recursive --force play/mybucket/ mc rm --recursive --force play/mybucket/myprefix/
Consider first running the command with the
--dry-runflag 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 object locking.
- --dangerous
- Optional
Allows running
mc rmwhen theALIASspecifies the root (all buckets) on the MinIO deployment.When combined with
--versions, this flag directsmc rmto permanently remove all objects and versions from theALIAStarget.Consider first running the command with the
--dry-runto validate the scope of the site-wide delete operation.Warning
Running
mc rm --dangerouswith the--versionsflag is irreversible. Exercise all possible due diligence in ensuring the command applies to only the desiredALIAStargets 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 rmwith any of the following arguments:
- --incomplete, I
- Optional
Remove incomplete uploads for the specified object.
If any
ALIASspecifies 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#ssformat. For example:--newer-than 1d2hh3mm4ssDefaults to
0(all objects).
- --non-current
- Optional
Removes all non-current object versions from the specified
ALIAS.This option has no effect on buckets without versioning enabled.
- --older-than
- Optional
Remove object(s) older than the specified time limit. Specify a string in
#d#h#m#sformat. 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
--versionsflag to recursively remove all objects and object versions from the bucket.Consider first running the command with the
--dry-runflag to validate the scope of the recursive delete operation.Mutually exclusive with
mc rm --version-id
- --rewind
- Optional
Directs
mc rmto operate only on the object version(s) that existed at specified point-in-time.To rewind to a specific date in the past, specify the date as an ISO8601-formatted timestamp. For example:
--rewind "2020.03.24T10:00".To rewind a duration in time, specify the duration as a string in
#d#hh#mm#ssformat. For example:--rewind "1d2hh3mm4ss".
--rewindrequires that the specifiedALIASbe an S3-compatible service that supports Bucket Versioning. For MinIO deployments, usemc versionto enable or disable bucket versioning.
- --versions
- Optional
Directs
mc rmto operate on all object versions that exist in the bucket.--versionsrequires that the specifiedALIASbe an S3-compatible service that supports Bucket Versioning. For MinIO deployments, usemc versionto enable or disable bucket versioning.Use
--versionsand--rewindtogether to remove all object versions which existed at a specific point in time.
- --version-id, vid
- Optional
Directs
mc rmto operate only on the specified object version.--version-idrequires that the specifiedALIASbe an S3-compatible service that supports Bucket Versioning. For MinIO deployments, usemc versionto 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
mc rm ALIAS/PATH
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
Replace
ALIASwith thealiasof a configured S3-compatible service.Replace
PATHwith 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 --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
Replace
ALIASwith thealiasof a configured S3-compatible service.Replace
PATHwith the path to the object. For example,/mybucket/myobject.Replace
DURATIONwith 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.
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/2021/january/myphoto.jpgphotos/2021/february/myotherphoto.jpgphotos/NYE21/NewYears.jpg
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 removes
myotherphoto.jpg, the removal API automatically trims both the /february
prefix and the now-empty /2021 prefix. If an mc command removes
NewYears.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.
To remove a specific object version from a bucket, use
mc rm --version-idTo remove all versions of an object from a bucket, use
mc rm --versionsTo remove all non-current versions of an object from a bucket, use
mc rm --non-current
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 mc commands may work as documented, any such usage is at your own risk.