Rm command¶
Removes a “folder” or a set of files matching a pattern. Use with caution.
Note
rm
is a high-level command that under the hood utilizes multiple calls to the server,
which means the server cannot guarantee consistency between multiple operations. For
example if a file matching a pattern is uploaded during a run of rm
command, it MIGHT
be deleted (as “latest”) instead of the one present when the rm
run has started.
In order to safely delete a single file version, please use delete-file-version
.
To list (but not remove) files to be deleted, use --dryRun
. You can also
list files via ls
command - the listing behaviour is exactly the same.
Progress is displayed on the console unless --noProgress
is specified.
Use –threads to manually adjust number of threads used in the operation. Otherwise, the number of threads will be automatically chosen.
The --versions
option selects all versions of each file, not
just the most recent.
The --recursive
option will descend into folders, and will select
only files, not folders.
The --withWildcard
option will allow using *
, ?
and `[]`
characters in folderName
as a greedy wildcard, single character
wildcard and range of characters. It requires the --recursive
option.
Remember to quote folderName
to avoid shell expansion.
The --dryRun
option prints all the files that would be affected by
the command, but removes nothing.
Normally, when an error happens during file removal, log is printed and the command
goes further. If any error should be immediately breaking the command,
--failFast
can be passed to ensure that first error will stop the execution.
This could be useful to e.g. check whether provided credentials have deleteFiles
capabilities.
Note
Using --failFast
doesn’t prevent the command from trying to remove further files.
It just stops the progress. Since multiple files are removed in parallel, it’s possible
that just some of them were not reported.
Command returns 0 if all files were removed successfully and a value different from 0 if any file was left.
Examples.
Note
Note the use of quotes, to ensure that special characters are not expanded by the shell.
Note
Use with caution. Running examples presented below can cause data-loss.
Remove all csv and tsv files (in any directory, in the whole bucket):
b2 rm --recursive --withWildcard bucketName "*.[ct]sv"
Remove all info.txt files from buckets bX, where X is any character:
b2 rm --recursive --withWildcard bucketName "b?/info.txt"
Remove all pdf files from buckets b0 to b9 (including sub-directories):
b2 rm --recursive --withWildcard bucketName "b[0-9]/*.pdf"
Requires capability:
listFiles
deleteFiles
b2 rm [-h] [--profile PROFILE] [--dryRun] [--queueSize QUEUESIZE]
[--noProgress] [--failFast] [--threads THREADS] [--versions]
[--recursive] [--withWildcard]
bucketName [folderName]
Positional Arguments¶
- bucketName
- folderName
Named Arguments¶
- --profile
- --dryRun
Default: False
- --queueSize
max elements fetched at once for removal, if left unset defaults to twice the number of threads.
- --noProgress
Default: False
- --failFast
Default: False
- --threads
- --versions
Default: False
- --recursive
Default: False
- --withWildcard
Default: False